Open Cnoor0171 opened 4 weeks ago
A similar problem if the methods are classmethods
from typing import Self
class MyBase1:
@classmethod
def foo(cls) -> Self:
return cls()
class MyBase2:
@classmethod
def foo(cls) -> Self:
return cls()
class MyDerived(MyBase1, MyBase2):
pass
MyBase1.foo() # Should be Valid. Has type MyBase1
MyBase1.foo() # Should be Valid. Has type MyBase2
MyDerived.foo() # Should be Valid. Has type MyDerived
Interestingly, mypy is also able to derive the correct type of MyDerived.foo()
or MyDerived().foo()
if you do reveal_type
on them.
Bug Report
If you try to derive from multiple base classes that both define the same function returning
Self
, mypy incorrectly warns that the definitions are incompatible.To Reproduce
Expected Behavior
Shouldn't report any errors. In the context of the line
class MyDerived(MyBase1, MyBase2):
bothMyBase1
andMyBase2
returnsSelf
akaMyDerived
Actual Behavior
Your Environment
mypy.ini
(and other config files):