-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix 0.750 regression: union (non-)simplification should not affect inference #8077
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix!
mypy/constraints.py
Outdated
@@ -108,6 +108,12 @@ def _infer_constraints(template: Type, actual: Type, | |||
template = get_proper_type(template) | |||
actual = get_proper_type(actual) | |||
|
|||
# Type inference shouldn't be affected by whether union types have bee simplified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: been
@@ -3646,7 +3646,7 @@ def test_narrow_none() -> None: | |||
a: Optional[int] | |||
if int(): | |||
a = narrow_none(a) | |||
reveal_type(a) # N: Revealed type is 'Union[builtins.int, None]' | |||
reveal_type(a) # N: Revealed type is 'builtins.int' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice improvement too.
Fixes #8051
The fix is as discussed in the issue. I didn't find a test case for the union
actual
, but I think it makes sense to simplify it as well. Note: I add thepythoneval
test just as a regression test, if you think it is not worth it, I can remove it.