Closed
Description
Bug Report
Mypy fails to identify missing value comparisons in my match
when I use |
To Reproduce
from typing import Literal, assert_never
Color = Literal["blue", "green", "red"]
def print_color(color: Color) -> None:
match color:
case "blue":
print("blue")
case "green" | "kangaroo":
print("green")
case _:
assert_never(color)
Expected Behavior
I expected mypy to error because I missed checking against red
colors.py:13: error: Argument 1 to "assert_never" has incompatible type "Literal['red']"; expected "Never" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Actual Behavior
Mypy doesn't raise any errors
Success: no issues found in 1 source file
** Extra Context **
This only happens when I use |
.
I don't use pyright but ran it to see if I was the one missing something but I believe they do flag it correctly
colors.py:13:24 - error: Argument of type "Literal['red']" cannot be assigned to parameter "arg" of type "Never" in function "assert_never"
Type "Literal['red']" is not assignable to type "Never" (reportArgumentType)
Your Environment
- Mypy version used:
mypy 1.13.0 (compiled: yes)
- Mypy command-line flags:
--strict
- Python version used:
Python 3.11.6