Originally posted on gitter july 29th, where it was suggested I open a bug report
Bug Report
For this code:
from typing import Generic, TypeVar, Union
ListT = TypeVar("ListT", str, float)
class TestListA(Generic[ListT]):
def __init__(self, device: ListT) -> None:
self._device: ListT = device
class TestListB(TestListA[ListT]):
def __init__(self, device: ListT) -> None:
super().__init__(device)
mypy outputs error:
test.py:13: error: Argument 1 to "__init__" of "TestListA" has incompatible type "str"; expected "ListT" [arg-type]
test.py:13: error: Argument 1 to "__init__" of "TestListA" has incompatible type "float"; expected "ListT" [arg-type]
which is false positive.
Please note that when using a TypeVar with bound=Union, then mypy doesn't complain.
ListT = TypeVar("ListT", bound=Union[str, float])
Your Environment
- Mypy version used:
mypy 0.971 (compiled: yes)
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini (and other config files):
- Python version used:
Python 3.9.12
- Operating system and version:
Originally posted on gitter july 29th, where it was suggested I open a bug report
Bug Report
For this code:
mypy outputs error:
which is false positive.
Please note that when using a
TypeVarwithbound=Union, thenmypydoesn't complain.Your Environment
mypy 0.971 (compiled: yes)mypy.ini(and other config files):Python 3.9.12