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
Are you reporting a bug, or opening a feature request?
Bug
Please insert below the code you are checking with mypy:
fromtypingimportUniondefconvert(num: Union[str, int]) ->int:
iftype(num) isstr:
returnint(num)
#since we returned above, this can only be an `int`returnnumprint( convert("1") +convert(2) )
What is the actual behavior/output?
test.py:8: error: Incompatible return value type (got "Union[str, int]", expected "int")
What is the behavior/output you expect?
No error.
What are the versions of mypy and Python you are using?
mypy 0.761
Python 3.6.9
Do you see the same issue after installing mypy from Git master?
Did not check with master.
What are the mypy flags you are using? (For example --strict-optional)
None.
This is similar to #8264 such that the type is not deduced.
If there is N types in the Union, and one of the if statements return for a given type, there should be N-1 valid types in the Union proceeding the if statement.
This can get annoying when I have to cast the variable when I know the type:
Things should work as expected if you use isinstance(num, str) instead of type(num) is str. The type(...) is check is not recommended since it doesn't work with subclasses (of str, in this case).
Bug
test.py:8: error: Incompatible return value type (got "Union[str, int]", expected "int")
No error.
Did not check with master.
None.
This is similar to #8264 such that the type is not deduced.
If there is
N
types in theUnion
, and one of theif
statements return for a given type, there should beN-1
valid types in theUnion
proceeding the if statement.This can get annoying when I have to cast the variable when I know the type:
The text was updated successfully, but these errors were encountered: