-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
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
# https://mypy-play.net/?mypy=latest&python=3.12&gist=e5d3734df862e8f3ada5c11c076cae57
# main.py
from typing import Self
class MyBase1:
def foo(self) -> Self:
return self
class MyBase2:
def foo(self) -> Self:
return self
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 MyDerivedExpected Behavior
Shouldn't report any errors. In the context of the line class MyDerived(MyBase1, MyBase2): both MyBase1 and MyBase2 returns Self aka MyDerived
Actual Behavior
$ mypy main.py
main.py:13: error: Definition of "foo" in base class "MyBase1" is incompatible with definition in base class "MyBase2" [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: mypy 1.11.1 (compiled: yes)
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.12
jisaacstone
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong