From bb133ade2d217a05b1a0563eed9488bd1d89afa8 Mon Sep 17 00:00:00 2001 From: Leo Ji Date: Tue, 31 Mar 2026 22:36:45 +0000 Subject: [PATCH] fix: use 'parameter' instead of 'argument' in missing-self error message The error message for methods defined without any parameters said 'argument' but the correct term in the context of a function definition is 'parameter'. Update the message and all related test fixtures. Closes #20939 Made-with: Cursor --- mypy/checker.py | 3 ++- test-data/unit/check-classes.test | 26 +++++++++++++------------- test-data/unit/check-functions.test | 2 +- test-data/unit/check-super.test | 2 +- test-data/unit/fine-grained.test | 12 ++++++------ 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 7d0b5dbde09d8..fce2b5c736660 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1631,7 +1631,8 @@ def require_correct_self_argument(self, func: Type, defn: FuncDef) -> bool: if not func.arg_types: self.fail( - 'Method must have at least one argument. Did you forget the "self" argument?', defn + 'Method must have at least one parameter. Did you forget the "self" parameter?', + defn, ) return False diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 5a66eff2bd3b7..51ad6a8677f26 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -3336,7 +3336,7 @@ from typing import Any class Test: def __setattr__() -> None: ... \ # E: Invalid signature "Callable[[], None]" for "__setattr__" \ - # E: Method must have at least one argument. Did you forget the "self" argument? + # E: Method must have at least one parameter. Did you forget the "self" parameter? t = Test() t.crash = 'test' # E: Attribute function "__setattr__" with type "Callable[[], None]" does not accept self argument \ @@ -7829,7 +7829,7 @@ reveal_type(Foo().y) # N: Revealed type is "builtins.list[Any]" # flags: --check-untyped-defs class Foo: - def bad(): # E: Method must have at least one argument. Did you forget the "self" argument? + def bad(): # E: Method must have at least one parameter. Did you forget the "self" parameter? self.x = 0 # E: Name "self" is not defined [case testMethodSelfArgumentChecks] @@ -7848,7 +7848,7 @@ def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]: return fn class A: - def undecorated() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? + def undecorated() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter? def undecorated_not_self(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self) @@ -7875,7 +7875,7 @@ class A: return 0 @to_same_callable - def g1() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? + def g1() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter? @to_same_callable def g2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self) @@ -7937,11 +7937,11 @@ reveal_type(A().fn3) # N: Revealed type is "def (_x: builtins.int) -> builtins. class B: @remove_first # E: Argument 1 to "remove_first" has incompatible type "Callable[[], int]"; expected "Callable[[T], int]" - def fn1() -> int: # E: Method must have at least one argument. Did you forget the "self" argument? + def fn1() -> int: # E: Method must have at least one parameter. Did you forget the "self" parameter? return 0 @remove_first - def fn2(_x: int) -> int: # E: Method must have at least one argument. Did you forget the "self" argument? + def fn2(_x: int) -> int: # E: Method must have at least one parameter. Did you forget the "self" parameter? return 0 @remove_first @@ -8009,7 +8009,7 @@ def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]: def unchecked(): class Bad: - def fn() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? + def fn() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter? def fn2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self) # TODO: would be nice to make this error, but now we see the func @@ -8030,29 +8030,29 @@ def unchecked(): def checked() -> None: class Bad: - def fn() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? + def fn() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter? def fn2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self) @to_same_callable - def g() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? + def g() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter? @to_same_callable def g2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self) class AlsoBad: - def fn(): ... # E: Method must have at least one argument. Did you forget the "self" argument? + def fn(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter? def fn2(x): ... @to_same_callable - def g(): ... # E: Method must have at least one argument. Did you forget the "self" argument? + def g(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter? @to_same_callable def g2(x): ... class Ok: - def fn(): ... # E: Method must have at least one argument. Did you forget the "self" argument? + def fn(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter? def fn2(x): ... @to_same_callable - def g(): ... # E: Method must have at least one argument. Did you forget the "self" argument? + def g(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter? @to_same_callable def g2(x): ... [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 80a40d3ef1795..5cab320d084af 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2771,7 +2771,7 @@ class A: @dec def e(self) -> int: pass @property - def g() -> int: pass # E: Method must have at least one argument. Did you forget the "self" argument? + def g() -> int: pass # E: Method must have at least one parameter. Did you forget the "self" parameter? @property def h(self, *args, **kwargs) -> int: pass # OK [builtins fixtures/property.pyi] diff --git a/test-data/unit/check-super.test b/test-data/unit/check-super.test index 8816322a270af..c91e576a10f66 100644 --- a/test-data/unit/check-super.test +++ b/test-data/unit/check-super.test @@ -375,7 +375,7 @@ class A: return 1 class B(A): - def g() -> None: # E: Method must have at least one argument. Did you forget the "self" argument? + def g() -> None: # E: Method must have at least one parameter. Did you forget the "self" parameter? super().f() # E: "super()" requires one or two positional arguments in enclosing function def h(self) -> None: def a() -> None: diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index a1b9a8da98ffd..7acfcc6de07d2 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -1572,11 +1572,11 @@ class A: [file b.py.3] 2 [out] -a.py:3: error: Method must have at least one argument. Did you forget the "self" argument? +a.py:3: error: Method must have at least one parameter. Did you forget the "self" parameter? == -a.py:3: error: Method must have at least one argument. Did you forget the "self" argument? +a.py:3: error: Method must have at least one parameter. Did you forget the "self" parameter? == -a.py:3: error: Method must have at least one argument. Did you forget the "self" argument? +a.py:3: error: Method must have at least one parameter. Did you forget the "self" parameter? [case testBaseClassDeleted] import m @@ -1993,11 +1993,11 @@ class A: class A: def foo(self) -> int: pass [out] -a.py:2: error: Method must have at least one argument. Did you forget the "self" argument? +a.py:2: error: Method must have at least one parameter. Did you forget the "self" parameter? == -a.py:2: error: Method must have at least one argument. Did you forget the "self" argument? +a.py:2: error: Method must have at least one parameter. Did you forget the "self" parameter? == -a.py:2: error: Method must have at least one argument. Did you forget the "self" argument? +a.py:2: error: Method must have at least one parameter. Did you forget the "self" parameter? == [case testPreviousErrorInMethodSemanal2]