Closed as not planned
Description
Bug Report
Enums with only one member do not exhaustively match
correctly.
To Reproduce
from enum import Enum, auto
from typing_extensions import assert_never
class Color(Enum):
Red = auto()
def f(color: Color) -> None:
match color:
case Color.Red:
print("red")
case _ as unreachable:
assert_never(unreachable)
Expected Behavior
No type checking errors.
Actual Behavior
$ mypy main.py
main.py:15: error: Argument 1 to "assert_never" has incompatible type "Color"; expected "NoReturn" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Your Environment
$ pip list
Package Version
----------------- -------
mypy 0.991
mypy-extensions 0.4.3
pip 22.3.1
setuptools 65.6.3
tomli 2.0.1
typing_extensions 4.4.0
wheel 0.38.4
- Mypy version used: 0.991
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10.8
Additional Context
What's strange is that if the Enum
has at least 2 members, everything works correctly:
from enum import Enum, auto
from typing_extensions import assert_never
class Color(Enum):
Red = auto()
Blue = auto()
def f(color: Color) -> None:
match color:
case Color.Red:
print("red")
case Color.Blue:
print("blue")
case _ as unreachable:
assert_never(unreachable)