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
{{ message }}
Repository navigation
match-case does not work correctly with Literals vs Enums #20142
main.py:14: error: Statement is unreachable [unreachable]
main.py:18: error: Argument 1 to "assert_never" has incompatible type "Literal['g']"; expected "Never" [arg-type]
main.py:27: error: Statement is unreachable [unreachable]
main.py:29: error: Argument 1 to "assert_never" has incompatible type "Literal[Color.BLUE]"; expected "Never" [arg-type]
#19594 should (at least partially) address this issue: it will still report fallback assert_never as failing (and I'm not sure whether that's correct), but reveal_type will be reachable and reveal Literal[Color.Green] and Literal["b"], resp.
but reveal_type will be reachable and reveal Literal[Color.Green] and Literal["b"], resp.
Uhm, that is exactly the wrong way around. The literal and value patterns are equality based, so in the first case it should be Literal["g"] and in the latter it should be Literal[Color.BLUE]. Alex actually added some nice extra detail in his issue report in ty after I brought this problem up in discourse.
Activity
sterliakov commentedon Oct 30, 2025
#19594 should (at least partially) address this issue: it will still report fallback
assert_neveras failing (and I'm not sure whether that's correct), butreveal_typewill be reachable and revealLiteral[Color.Green]andLiteral["b"], resp.randolf-scholz commentedon Oct 30, 2025
Uhm, that is exactly the wrong way around. The literal and value patterns are equality based, so in the first case it should be
Literal["g"]and in the latter it should beLiteral[Color.BLUE]. Alex actually added some nice extra detail in his issue report in ty after I brought this problem up in discourse.sterliakov commentedon Oct 30, 2025
Ough, and you're right, otherwise
will pass. Thanks!
This is a nice observation. I wonder why
visit_value_patternusesconditional_types_with_intersectioninstead of the equality helper then...Do not treat `match` value patterns as `isinstance` checks (#20146)