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
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.
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
amust 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_matchfunction, and no error for thebar_isinstancefunction.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