Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,8 @@ def prepare_method_signature(self, func: FuncDef, info: TypeInfo, has_self_type:
elif isinstance(functype, CallableType):
self_type = get_proper_type(functype.arg_types[0])
if isinstance(self_type, AnyType):
if has_self_type:
assert self.type is not None and self.type.self_type is not None
leading_type: Type = self.type.self_type
else:
leading_type = fill_typevars(info)
self.setup_self_type()
leading_type: Type = info.self_type
if func.is_class or func.name == "__new__":
leading_type = self.class_type(leading_type)
func.type = replace_implicit_first_type(functype, leading_type)
Expand Down
5 changes: 2 additions & 3 deletions test-data/unit/check-selftype.test
Original file line number Diff line number Diff line change
Expand Up @@ -1692,9 +1692,8 @@ class C:
return self
def baz(self: Self) -> None:
self.x = self
def bad(self) -> None:
# This is unfortunate, but required by PEP 484
self.x = self # E: Incompatible types in assignment (expression has type "C", variable has type "Self")
def eggs(self) -> None:
self.x = self

[case testTypingSelfClashInBodies]
from typing import Self, TypeVar
Expand Down