-
-
Couldn't load subscription status.
- Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
A Generic class that is a subclass of a class with a __new__() declared where there is a TypeVar as a parameter of __new__() reports that "Type application has too few types"
To Reproduce
from __future__ import annotations
from typing import Generic, Sequence, TypeVar, Union
T1 = TypeVar("T1", Sequence, list)
T2 = TypeVar("T2")
class Base:
def __new__(cls, data: T1 | str) -> Base:
...
def meth(self, data: T1 | str) -> int:
...
class GenBase(Base, Generic[T2]):
...
def fun() -> GenBase[int]:
return GenBase[int]("ac")Actual Behavior
mypy 0.971 reports:
gentypevar.py:21: error: Returning Any from function declared to return "GenBase[int]"
gentypevar.py:21: error: Type application has too few types (2 expected)
Your Environment
- Mypy version used: 0.971
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.8
- Operating system and version: Windows 10
Note that if T1 is changed to a Union, then no error is reported:
from __future__ import annotations
from typing import Generic, Sequence, TypeVar, Union
U1 = Union[Sequence, list, str]
T2 = TypeVar("T2")
class Base2:
def __new__(cls, data: U1 | str) -> Base2:
...
def meth(self, data: U1 | str) -> int:
...
class GenBase2(Base2, Generic[T2]):
...
def fun2() -> GenBase2[int]:
return GenBase2[int]("ac")This came up with the pandas-stubs project. pandas-dev/pandas-stubs#197
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong