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
In cases like this mypy doesn't narrow down the type in assignment:
x: Union[int, str] =0# type of x is Union[int, str] here!
Any assignment after the initial declaration will narrow the type down:
x: Union[int, str]
x=0# type of x is int here!
Document this behavior since it can be surprising. The motivation for this is that this behavior makes it easy to override the inferred type for a variable, which is sometimes useful.
The text was updated successfully, but these errors were encountered:
@tz-earl I'm sorry we dropped your question. This is a very busy project, with an all volunteer crew! I think the right place to document this would be a new section in Type inference and type annotations, perhaps right after Explicit types for variables.
In cases like this mypy doesn't narrow down the type in assignment:
Any assignment after the initial declaration will narrow the type down:
Document this behavior since it can be surprising. The motivation for this is that this behavior makes it easy to override the inferred type for a variable, which is sometimes useful.
The text was updated successfully, but these errors were encountered: