Skip to content

[1.16 regression] failure to exhaustively narrow type var bounded by union with value pattern match #19159

Description

@hauntsaninja

Courtesy of @delfick

So if we have two files

# a.pyfromtypingimportassert_neverimportbdefswitch[T_Choice: b.One|b.Two](choice: type[T_Choice]) ->None:
matchchoice:
caseb.One:
print(1)
caseb.Two:
print(2)
case _:
assert_never(choice)
switch(b.One)

and

# b.pyclassOne: ...
classTwo: ...

Then I get no errors with mypy 1.15 and this error with 1.16

a.py:13: error: Argument 1 to "assert_never" has incompatible type "type[Two] | Never"; expected "Never" [arg-type]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statementtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions