-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type of conditional expression is join instead of union #3487
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
Comments
cc @carljm |
Comment related to #2464. The following shouldn't produce an error either.
If A and B have a common ancestor, it makes sense to use it. But if it turns out to be |
Bumped priority to high since the workaround is non-trivial and this seems to be affecting multiple users. |
I'm working on this. |
So is the new behavior expected to be that the types of conditional expressions are unions instead of joins? I'm not seeing that. I'm on mypy 0.701 and when I run this code in mypy
I get
Based on my understanding of the resolution of this issue I'd expect the type to |
It is still a union in union context. |
Should this be reopened? Here is another use case:
This happens because |
@cjolowicz Can you open a separate follow-up issue about your use case? |
The type of expression such as
1 if foo else 'x'
isobject
(join ofint
andstr
). This is surprising and if such an expression is used in a union type context, the result is often not what's expected. Example:This is also arguably inconsistent, as the
or
andand
operators produce union types. For example, the type of(1+2) or 'x'
isUnion[int, str]
.Maybe conditional expressions should also produce unions? An alternative idea is to only produce union types if the type context is a union type, but this would be somewhat ad-hoc.
The text was updated successfully, but these errors were encountered: