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
fromtypingimport*deff(a: Union[int, str]) ->int:
ifisinstance(a, str):
return-1definner() ->int:
returna+1# E: Unsupported operand types for + ("Union[int, str]" and "int"returninner()
Note that when inner() is defined, and also when it's called, a can only be an int. But we still get an error.
I ran into this when checking some real-world code against strict optional -- there the union was Optional[int] and the type restriction was if a is not None, but it's the same problem.
The text was updated successfully, but these errors were encountered:
I think this is quite difficult to do correctly. This is correct because f exits before inner is defined, but wouldn't be correct for other local information about types. For example:
fromtypingimport*deff(a: Union[int, str]) ->int:
ifisinstance(a, str):
return-1else:
definner() ->int:
returna+1# E: Unsupported operand types for + ("Union[int, str]" and "int"a="foo"returninner()
The binder doesn't keep track of this information at the moment -- I'm not sure how hard it would be to add, but probably not super easy.
Example:
Note that when inner() is defined, and also when it's called, a can only be an int. But we still get an error.
I ran into this when checking some real-world code against strict optional -- there the union was Optional[int] and the type restriction was
if a is not None
, but it's the same problem.The text was updated successfully, but these errors were encountered: