-
-
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
Fix single item enum match type exhaustion #16966
Fix single item enum match type exhaustion #16966
Conversation
This comment has been minimized.
This comment has been minimized.
5cc30c9
to
60f6c4a
Compare
test-data/unit/check-python310.test
Outdated
@@ -1369,6 +1369,35 @@ match m3: | |||
reveal_type(m3) # N: Revealed type is "Tuple[Union[builtins.int, builtins.str]]" | |||
[builtins fixtures/tuple.pyi] | |||
|
|||
[case testMatchEnumMultipleChoices] |
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 case is not strictly needed for this change. It just demonstrates how this should work normally. But I would think this is already covered. What do you think?
This comment has been minimized.
This comment has been minimized.
60f6c4a
to
14699cb
Compare
This comment has been minimized.
This comment has been minimized.
14699cb
to
885a84e
Compare
@@ -202,7 +202,7 @@ def visit_value_pattern(self, o: ValuePattern) -> PatternType: | |||
typ = self.chk.expr_checker.accept(o.expr) | |||
typ = coerce_to_literal(typ) | |||
narrowed_type, rest_type = self.chk.conditional_types_with_intersection( | |||
current_type, [get_type_range(typ)], o, default=current_type | |||
current_type, [get_type_range(typ)], o, default=get_proper_type(typ) |
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.
The issue was that on mypy/checker.py
on conditional_types
function, which is called by this self.chk.conditional_types_with_intersection
, the conditional_types
returns from here the default value:
Line 7399 in 2037e4a
return default, UninhabitedType() |
When on regular enum that has multiple choices the conditional_types
returns here instead:
Line 7415 in 2037e4a
return proposed_type, remaining_type |
But the first one returns wrong default value, so I am changing the default value here to be what the get_proper_type
returns instead.
This comment has been minimized.
This comment has been minimized.
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, this looks good to me (just made a minor tweak to the tests)
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #14109