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
injust
changed the title
Pattern matching is not exhaustive if enum member subject is accessed by name and the name is in a variable
Pattern matching is not exhaustive in a weird edge case with an enum member subject
Apr 3, 2025
Given that your good version works, is it the same as #18440? Currently we do not narrow types of complex expressions in match statement other than function calls.
Given that your good version works, is it the same as #18440? Currently we do not narrow types of complex expressions in match statement other than function calls.
Yes, it seems like the same issue. In the repro for #18440, if you change the function b from
matchd[k]:
to
foo=d[k]
matchfoo:
Then it type checks. This is the same behaviour that I'm seeing here.
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
If you do this, mypy does not think the match statement is exhaustive.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=0d11136907ace743b0f2412ad0f26bb1
If you replace
Thing[two]
withThing["TWO"]
, the problem also goes away.Expected Behavior
Both match statements are exhaustive, so there is a return statement for all cases.
Actual Behavior
Your Environment
The text was updated successfully, but these errors were encountered: