Description
Bug Report
When there is only one member of the enum, mypy
doesn't perform full exhaustiveness checking and reaches assert_never
statement, although it shouldn't.
To Reproduce
Expected Behavior
mypy
does not complain and reports no errors
Actual Behavior
mypy
reaches unreachable code and complains
main.py:15: error: Argument 1 to "assert_never" has incompatible type "A"; expected "NoReturn" [arg-type]
Your Environment
Playground
Rationale
While having an enum with only one member is definitely a contrived example, it is a valid example nonetheless. This popped up for me while I was implementing a feature partially for just one case of an enum first with the plan of filing up more enum cases later on.
Note that this is specific for enums with one member only, if you have a Literal
with only one member, mypy
correctly deduces that unreachable code is truly unreachable. If you have an enum with multiple members (and an appropriate match-case block), the unreachable code is also correctly deduced.