Skip to content

Commit

Permalink
remove stupid error about erased self
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Nov 29, 2024
1 parent 5d36e12 commit 1944461
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,15 @@ def check_func_def(
# the consistency check will be performed at call sites.
msg = None
elif typ.arg_names[i] in {"self", "cls"}:
msg = message_registry.ERASED_SELF_TYPE_NOT_SUPERTYPE.format(
erased.str_with_options(self.options),
ref_type.str_with_options(self.options),
)
if mypy.options._based:
msg = None
else:
msg = (
message_registry.ERASED_SELF_TYPE_NOT_SUPERTYPE.format(
erased.str_with_options(self.options),
ref_type.str_with_options(self.options),
)
)
else:
msg = message_registry.MISSING_OR_INVALID_SELF_TYPE
if msg:
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-based-misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,13 @@ class B(A):
\[[tool.mypy.overrides]]
module="other"
work_not_properly_function_names=true


[case testErasedSelfType]

class A:
def f(self: B):
reveal_type(self) # N: Revealed type is "__main__.B"
class B(A): ...
A().f() # E: Invalid self argument "A" to attribute function "f" with type "def (self: B) -> None" [misc]
B().f() # no error

0 comments on commit 1944461

Please sign in to comment.