Type narrowing for tuple worse with match than with the equivalent instanceof check #19082
Labels
bug
mypy got something wrong
topic-match-statement
Python 3.10's match statement
topic-type-narrowing
Conditional type narrowing / binder
Bug Report
Type narrowing is worse in a match statement on a tuple than the equivalent isinstance check.
With isinstance, mypy is able to determine that the type of
a
must be the tuple side of the union even though the check is only against Sequence, and then correctly narrows the type of the second element. With match, mypy is unable to do so and gives a union of the two element types in the tuple.To Reproduce
repro.py
Expected Behavior
No errors
Actual Behavior
Note that there is only one error, for the
bar_match
function, and no error for thebar_isinstance
function.Your Environment
I found this with 1.15 and reproduced it on the current master branch.
mypy.ini
(and other config files): NonePossibly related issues:
#19081
The text was updated successfully, but these errors were encountered: