-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bool/float treated inconsistently with bool/int and int/float, causing inconsistent Union simplification #1850
Comments
I looked into this because I thought it might have been something I broke. Technically it was exposed by one of my changes, but the underlying issue is older. mypy thinks that I think maybe the right thing to do here is copy a class's Not really bugs, but also contributing to make this issue visible are:
|
Mypy should probably simplify all unions that are used internally. Having non-simplified unions is problematic, as parts of mypy likely assume that everything is simplified. I'm not sure whether we have enough information to perform simplification when doing semantic analysis of types, as this requires a full MRO and well-formed types -- we may have to do it on demand when we read types during type checking. Simplifying annotations might be a little unintuitive for users, as an annotation like |
I recall a discussion with @ddfisher where he was against always simplifying unions. (I can't find the specific issue -- maybe it was IRL. :-) |
I thought it was just that there was some bug with union simplification that was problematic? |
In any case, not simplifying unions should generally be harmless. The real issue here is that |
I think this is a decent example of where a fully fleshed-out formalism for mypy would be useful. |
I've retitled the issue to reflect Reid's observation. |
mypy can't even infer the proper return type if the annotation is as simple as |
bool is a subclass of int, so bool is an int. In what way do you expect a return type of |
l = [] # type: List[Union[bool, int, float]]
causes "error: Incompatible types in assignment (expression has type List[float], variable has type List[Union[bool, int, float]])"
I also tried
and they all pass.
The text was updated successfully, but these errors were encountered: