mypy没有__ sub __'的超载变体
我有这种情况:
def get_date_plus_n(d1 :Optional[date] , n:int) -> Optional[date] :
if d1 :
return d1 + n
else :
return None
def get_date_minus_n(d1 :Optional[date] , n:int) -> Optional[date] :
if d1 :
return d1 - n
else :
return None
def total(n:int) -> Optional[date]:
if get_date_plus_n(n) and get_date_minus_n() :
return get_date_plus_n(n)- get_date_minus_n(n)
else :
return None
但是我会得到此错误运行total():
error: No overload variant of "__sub__" of "date" matches argument type "None"
note: Possible overload variants:
note: def __sub__(self, timedelta) -> date
note: def __sub__(self, datetime) -> NoReturn
note: def __sub__(self, date) -> timedelta
note: Right operand is of type "Optional[date]"
idk如何处理此错误。在函数总数()中,我验证了先前方法的结果在应用 sub 方法之前是否有效,只是为了避免错误。但是显然,米皮不喜欢那样。
I have this case :
def get_date_plus_n(d1 :Optional[date] , n:int) -> Optional[date] :
if d1 :
return d1 + n
else :
return None
def get_date_minus_n(d1 :Optional[date] , n:int) -> Optional[date] :
if d1 :
return d1 - n
else :
return None
def total(n:int) -> Optional[date]:
if get_date_plus_n(n) and get_date_minus_n() :
return get_date_plus_n(n)- get_date_minus_n(n)
else :
return None
But I'm getting this error running total():
error: No overload variant of "__sub__" of "date" matches argument type "None"
note: Possible overload variants:
note: def __sub__(self, timedelta) -> date
note: def __sub__(self, datetime) -> NoReturn
note: def __sub__(self, date) -> timedelta
note: Right operand is of type "Optional[date]"
idk how to handle this error. In the function total() I verified if the result of the previous methods are valid before applying the sub method, just to avoid errors. But apparently, mipy does not like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论