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
While upgrading from 1.9 to 1.10 we found this regression in exhaustiveness checking. It looks like mypy stops inspecting a match expression once it's found an non-possible member.
importenumfromtypingimportassert_neverclassMember(enum.Enum):
b=enum.auto()
c=enum.auto()
deffn(value: Member) ->None:
ifvalueisMember.b:
returnmatchvalue:
case (
Member.b|Member.c
):
# No reveal is printed!reveal_type(value)
...
caseno_match:
assert_never(no_match)
It's probably also worth pointing out that order matters. Inverting order in the match expression to case Member.c | Member.b: makes the issue go away. I suspect an early return optimization to be at fault! 🕵️
Expected Behavior
This was caused by an already excluded member of the enum. The error message that mypy presents does not make this obvious and the fact that it presents it as an exhaustiveness failure I consider a bug that should be fixed.
The reveal_type() should contain both members .a and .c, there should be no type error.
It should be noted that we were able to work around this by removing the erroneously included member (Member.b in the minimal reproduction) from the match expression.
Actual Behavior
reveal_type() contains only .a, and there is a type error:
Bug Report
While upgrading from 1.9 to 1.10 we found this regression in exhaustiveness checking. It looks like mypy stops inspecting a match expression once it's found an non-possible member.
To Reproduce
Playground link for below, note it's passing on 1.9.
Related, removing
Member.a
causes thereveal_type()
to be muted!It's probably also worth pointing out that order matters. Inverting order in the match expression to
case Member.c | Member.b:
makes the issue go away. I suspect an early return optimization to be at fault! 🕵️Expected Behavior
This was caused by an already excluded member of the enum. The error message that mypy presents does not make this obvious and the fact that it presents it as an exhaustiveness failure I consider a bug that should be fixed.
The
reveal_type()
should contain both members.a
and.c
, there should be no type error.It should be noted that we were able to work around this by removing the erroneously included member (
Member.b
in the minimal reproduction) from the match expression.Actual Behavior
reveal_type()
contains only.a
, and there is a type error:Your Environment
See playground link.
The text was updated successfully, but these errors were encountered: