Skip to content

Commit ab8a8c3

Browse files
committed
Bind self to the current class when checking multiple inheritance compat
1 parent 9fffd9e commit ab8a8c3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ def bind_and_map_method(
22322232
is_class_method = sym.node.is_class
22332233

22342234
mapped_typ = cast(FunctionLike, map_type_from_supertype(typ, sub_info, super_info))
2235-
active_self_type = self.scope.active_self_type()
2235+
active_self_type = fill_typevars(sub_info)
22362236
if isinstance(mapped_typ, Overloaded) and active_self_type:
22372237
# If we have an overload, filter to overloads that match the self type.
22382238
# This avoids false positives for concrete subclasses of generic classes,

test-data/unit/check-generic-subtyping.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,3 +1220,23 @@ class D4(A[U], B[U]): pass
12201220
class D5(A[U], B[T]): pass # E: Definition of "fn" in base class "A" is incompatible with definition in base class "B" \
12211221
# E: Definition of "x" in base class "A" is incompatible with definition in base class "B"
12221222
[builtins fixtures/tuple.pyi]
1223+
1224+
[case testSelfInMultipleInheritance]
1225+
from typing_extensions import Self
1226+
1227+
class A:
1228+
foo: int
1229+
def method(self: Self, other: Self) -> None:
1230+
self.foo
1231+
other.foo
1232+
1233+
class B:
1234+
bar: str
1235+
def method(self: Self, other: Self) -> None:
1236+
self.bar
1237+
other.bar
1238+
1239+
class C(A, B): # OK: both methods take Self
1240+
pass
1241+
1242+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)