You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
results in a Unsupported operand types for + ("int" and "None")" error. Despite of the fact that f() can be called only with either (None, None) or (str, int) which is specified by the respective overloads, mypy cannot infer that if the first argument is not None, then the other argument also shouldn't be None.
Here is my use case where I find this inference would be helpful:
Without being able to infer that when x is an instance of A, func should be an instance of Callable[[C], bool] (which is specified by the overload variants), mypy results in the following error:
test.py:37: error: Argument 1 has incompatible type "Union[C, D]"; expected "C"
test.py:37: error: Argument 1 has incompatible type "Union[C, D]"; expected "D"
The text was updated successfully, but these errors were encountered:
Feature
Currently
mypy
cannot narrow down argument types in a function implementation based on function's overload variants. The following coderesults in a
Unsupported operand types for + ("int" and "None")"
error. Despite of the fact thatf()
can be called only with either(None, None)
or(str, int)
which is specified by the respective overloads,mypy
cannot infer that if the first argument is notNone
, then the other argument also shouldn't beNone
.Here is my use case where I find this inference would be helpful:
Without being able to infer that when
x
is an instance ofA
,func
should be an instance ofCallable[[C], bool]
(which is specified by the overload variants),mypy
results in the following error:The text was updated successfully, but these errors were encountered: