Open
Description
Bug Report
A TypeVar with multiple constraints can be seen as a union. However, the redundant-expr
does not understand it and emits errors which are wrong.
To Reproduce
from typing import TypeVar
T = TypeVar("T", int, str)
def foo(var: T) -> T:
return "aa" if isinstance(var, str) else 0
Expected Behavior
no error
Actual Behavior
foo.py:9:20: error: If condition is always false [redundant-expr]
return "aa" if isinstance(var, str) else 0
^~~~~~~~~~~~~~~~~~~~
foo.py:9:20: error: If condition is always true [redundant-expr]
return "aa" if isinstance(var, str) else 0
^~~~~~~~~~~~~~~~~~~~
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.14.1
- Mypy command-line flags:
--enable-error-code redundant-expr
- Python version used: 3.13.0