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
When you try to narrow down the type of a TypedDict by checking with a match expression, it produces an error when it shouldn't. But when you try an equivalent code but instead of using match, using if/else it works as expected.
Expected the code to be absent of errors since it's correct.
Actual Behavior
Produces an error in the index of payload with the key "version" saying that the other type (EmptyTaskPayload) does not have that key. Which is strange as the type system givs payload the correct type (SystemVersionTaskPayload) and in the alternative version with if/else it works.
Your Environment
Mypy version used: 1.8.0
Python version used: 3.10.12
The text was updated successfully, but these errors were encountered:
I don't think mypy currently supports discriminated unions of TypedDicts for pattern matching, so this isn't really a bug. It's a reasonable feature request, however. FWIW, pyright supports this feature.
Bug Report
When you try to narrow down the type of a
TypedDict
by checking with amatch
expression, it produces an error when it shouldn't. But when you try an equivalent code but instead of usingmatch
, usingif
/else
it works as expected.To Reproduce
Playground and Gist
Expected Behavior
Expected the code to be absent of errors since it's correct.
Actual Behavior
Produces an error in the index of
payload
with the key"version"
saying that the other type (EmptyTaskPayload
) does not have that key. Which is strange as the type system givspayload
the correct type (SystemVersionTaskPayload
) and in the alternative version withif
/else
it works.Your Environment
The text was updated successfully, but these errors were encountered: