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
fromtypingimportTypeVarT=TypeVar("T", int, str)
deffoo(var: T) ->T:
return"aa"ifisinstance(var, str) else0Expected 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
Bug Report
A TypeVar with multiple constraints can be seen as a union. However, the
redundant-exprdoes not understand it and emits errors which are wrong.To Reproduce
Expected Behavior
no error
Actual Behavior
Your Environment
--enable-error-code redundant-expr