-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-inheritanceInheritance and incompatible overridesInheritance and incompatible overridestopic-type-variables
Description
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:
mhaley-tignis
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-inheritanceInheritance and incompatible overridesInheritance and incompatible overridestopic-type-variables