Skip to content

Commit 073217d

Browse files
committed
Follow PEP 673 instead of PEP 484 when dealing with implicit self
1 parent 4635a8c commit 073217d

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

mypy/semanal.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,7 @@ def prepare_method_signature(self, func: FuncDef, info: TypeInfo, has_self_type:
972972
elif isinstance(functype, CallableType):
973973
self_type = get_proper_type(functype.arg_types[0])
974974
if isinstance(self_type, AnyType):
975-
if has_self_type:
976-
assert self.type is not None and self.type.self_type is not None
977-
leading_type: Type = self.type.self_type
978-
else:
979-
leading_type = fill_typevars(info)
975+
leading_type = info.self_type if info.self_type else fill_typevars(info)
980976
if func.is_class or func.name == "__new__":
981977
leading_type = self.class_type(leading_type)
982978
func.type = replace_implicit_first_type(functype, leading_type)

test-data/unit/check-selftype.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,9 +1692,8 @@ class C:
16921692
return self
16931693
def baz(self: Self) -> None:
16941694
self.x = self
1695-
def bad(self) -> None:
1696-
# This is unfortunate, but required by PEP 484
1697-
self.x = self # E: Incompatible types in assignment (expression has type "C", variable has type "Self")
1695+
def eggs(self) -> None:
1696+
self.x = self
16981697

16991698
[case testTypingSelfClashInBodies]
17001699
from typing import Self, TypeVar

0 commit comments

Comments
 (0)