mypy
mypy copied to clipboard
`TypeVar` has incompatible type when used `Self`
Bug Report
I'm not sure what's going on, better check the example. Also mypy experts, please forgive me if this is intentional behavior and not a bug.
To Reproduce
import typing
class A: pass
class B: pass
T = typing.TypeVar('T', A, B)
class C(typing.Generic[T]):
def method_A(self, argument: T) -> None: pass
def method_C(self, argument: T) -> typing.Self:
self.method_A(argument)
return self
Actual Behavior
main.py:13: error: Argument 1 to "method_A" of "C" has incompatible type "A"; expected "T" [arg-type]
main.py:13: error: Argument 1 to "method_A" of "C" has incompatible type "B"; expected "T" [arg-type]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: mypy 1.0.0+dev.9183b28401bd2928d921a068bbbc7e6565e77649 (compiled: no)
- Mypy command-line flags: none required to reproduce
- Mypy configuration options from
mypy.ini(and other config files): none required to reproduce - Python version used: 3.11