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
We should not generally infer union types like this, as it would probably be too confusing. This would only be used for None and potentially in cases where there is a non-trivial common supertype, such as in cases like this:
class Animal: ...
class Dog(Animal): ...
class Cat(Animal): ...
if c:
x = Dog()
else:
x = Cat()
# Type of x is Animal? Maybe even Union[Cat, Dog] since Cat and Dog are related, but we don't
# want to generate unions such as Union[int, str], I think, unless x is explicitly declared
# to have a union type.
JukkaL
changed the title
More general type inference
Type inference for multi-statement initialization
Jul 25, 2014
Improve type inference by making it possible to infer the type of a variable from multiple (conditional) assignments.
This should be valid:
Another example:
Later on, we could extend this to precise typing of None values using union types.
Edit: restricted this issue to multiple initialization.
The text was updated successfully, but these errors were encountered: