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
[1.16 regression] failure to exhaustively narrow type var bounded by union with value pattern match #19159
I would say though that I think the above example should probably only work if the two classes are decorated with @typing.final and it does seem the same errors happen with that decorator being used (i.e. no error in 1.15, that new error in 1.16)
I'm a little surprised that we apparently don't have a test for this. This looks like a significant regression, though it wasn't obvious likely because many projects we test against still support 3.9, which doesn't support the match statement.
I may not have time to properly look into this until weekend, but FWIW this looks really niche to me. I would even say we may go ahead with the release and fix this later, unless this causes big troubles for some repos.
changed the title [-][1.16 regression] failure to exhaustively narrow type var bounded by union[/-][+][1.16 regression] failure to exhaustively narrow type var bounded by union (across files)[/+]on Jun 4, 2025
changed the title [-][1.16 regression] failure to exhaustively narrow type var bounded by union (across files)[/-][+][1.16 regression] failure to exhaustively narrow type var bounded by union with value pattern match[/+]on Jun 29, 2025
In the original example, I think it is correct for mypy to complain about the assert_never because this case will be selected at runtime if we make a class A(b.One) and call switch(A). Value patterns are evaluated by equality (==).
Activity
hauntsaninja commentedon May 28, 2025
Bisects to #18972
delfick commentedon May 28, 2025
I would say though that I think the above example should probably only work if the two classes are decorated with
@typing.finaland it does seem the same errors happen with that decorator being used (i.e. no error in 1.15, that new error in 1.16)JukkaL commentedon May 28, 2025
I'm a little surprised that we apparently don't have a test for this. This looks like a significant regression, though it wasn't obvious likely because many projects we test against still support 3.9, which doesn't support the match statement.
cc @ilevkivskyi as the author of #18972
JukkaL commentedon May 28, 2025
I didn't realized that this only happens in a fairly specific scenario. Having everything in a single file doesn't reproduce the issue.
ilevkivskyi commentedon May 28, 2025
I may not have time to properly look into this until weekend, but FWIW this looks really niche to me. I would even say we may go ahead with the release and fix this later, unless this causes big troubles for some repos.
JukkaL commentedon May 28, 2025
Ok, I treat this as a non-blocker for the release.
delfick commentedon May 28, 2025
Ok, that's fine on my end, there's only a few
assert_neverthat I would have to change to an Exception in my repo :)[-][1.16 regression] failure to exhaustively narrow type var bounded by union[/-][+][1.16 regression] failure to exhaustively narrow type var bounded by union (across files)[/+]Only erase instances when checking runtime cover
Avoid erasing type objects when checking runtime cover (#19320)
hauntsaninja commentedon Jun 29, 2025
Btw I improved some behaviour here in #19320 , but we do not still exhaustively narrow so leaving this open
[-][1.16 regression] failure to exhaustively narrow type var bounded by union (across files)[/-][+][1.16 regression] failure to exhaustively narrow type var bounded by union with value pattern match[/+]randolf-scholz commentedon Dec 9, 2025
In the original example, I think it is correct for
mypyto complain about theassert_neverbecause this case will be selected at runtime if we make aclass A(b.One)and callswitch(A). Value patterns are evaluated by equality (==).hauntsaninja commentedon Dec 14, 2025
Closing this as per above and discussion in #20146