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
fromtypingimportUniondeffoo(bar: Union[str, int]):
ifbarin ["a", "b", "c"]:
# to a human, bar is clearly a str. mypy still thinks it's a Union[str, int]returnbar.upper()
else:
returnbar
$ mypy test.py
test.py:5: error: Item "int" of "Union[str, int]" has no attribute "upper"
The same thing happens if the condition is, for example, bar == "a".
Are you reporting a bug, or opening a feature request?
Feature request
What is the behavior/output you expect?
Mypy to understand the effect of conditions like bar == "a" or bar in ["a"], like it already does with isinstance checks
The text was updated successfully, but these errors were encountered:
jackriccomini
changed the title
Type is too generic after equality or membership check
Not inferring more specific type after equality or membership check
Dec 7, 2018
jackriccomini
changed the title
Not inferring more specific type after equality or membership check
Infer more specific type after equality or membership check
Dec 7, 2018
The same thing happens if the condition is, for example,
bar == "a"
.Feature request
Mypy to understand the effect of conditions like
bar == "a"
orbar in ["a"]
, like it already does withisinstance
checksThe text was updated successfully, but these errors were encountered: