Closed
Description
Bug Report
I encounter a false positive using mypy when a Generic class indirectly calls a method defined in its GrandParent.
To Reproduce
from typing import Generic, TypeVar
T = TypeVar("T")
class Grandparent(Generic[T]):
def say_hello(self) -> str:
return "Hello"
class Parent(Grandparent[T]):
pass
class Child(Parent[T]):
def say_hello(self) -> str:
return Parent.say_hello(self)
Expected Behavior
No error when running mypy.
Actual Behavior
I get this error:
error: Argument 1 to "say_hello" of "Grandparent" has incompatible type "Child[T]"; expected "Grandparent[T]" [arg-type]
Removing the Generic types, calling Grandparent.say_hello(self)
from the child, redefining the method in the Parent fixes the error.
Your Environment
- Mypy version used: 1.2.0
- Python version used: 3.10.0