Bug Report
not isinstance check fails to narrow type for a TypeVar with a union bound.
To Reproduce
fromtypingimportTypeVarT=TypeVar("T", bound=int|str)
deffoo(x: T) ->None:
ifnotisinstance(x, int):
reveal_type(x)https://mypy-play.net/?mypy=latest&python=3.11&gist=2be94d37f0b12222d62a7f40e59fb152
Expected Behavior
Revealed type is "builtins.str".
Actual Behavior
Revealed type is "T`-1".
Your Environment
- Mypy version used: 1.4.1
- Python version used: 3.10.6
Bug Report
not isinstancecheck fails to narrow type for a TypeVar with a union bound.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=2be94d37f0b12222d62a7f40e59fb152
Expected Behavior
Revealed type is "builtins.str".
Actual Behavior
Revealed type is "T`-1".
Your Environment