Skip to content

Commit bb133ad

Browse files
author
Leo Ji
committed
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
1 parent 25b210d commit bb133ad

5 files changed

Lines changed: 23 additions & 22 deletions

File tree

mypy/checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,8 @@ def require_correct_self_argument(self, func: Type, defn: FuncDef) -> bool:
16311631

16321632
if not func.arg_types:
16331633
self.fail(
1634-
'Method must have at least one argument. Did you forget the "self" argument?', defn
1634+
'Method must have at least one parameter. Did you forget the "self" parameter?',
1635+
defn,
16351636
)
16361637
return False
16371638

test-data/unit/check-classes.test

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,7 @@ from typing import Any
33363336
class Test:
33373337
def __setattr__() -> None: ... \
33383338
# E: Invalid signature "Callable[[], None]" for "__setattr__" \
3339-
# E: Method must have at least one argument. Did you forget the "self" argument?
3339+
# E: Method must have at least one parameter. Did you forget the "self" parameter?
33403340

33413341
t = Test()
33423342
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]"
78297829
# flags: --check-untyped-defs
78307830

78317831
class Foo:
7832-
def bad(): # E: Method must have at least one argument. Did you forget the "self" argument?
7832+
def bad(): # E: Method must have at least one parameter. Did you forget the "self" parameter?
78337833
self.x = 0 # E: Name "self" is not defined
78347834

78357835
[case testMethodSelfArgumentChecks]
@@ -7848,7 +7848,7 @@ def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]:
78487848
return fn
78497849

78507850
class A:
7851-
def undecorated() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
7851+
def undecorated() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
78527852

78537853
def undecorated_not_self(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self)
78547854

@@ -7875,7 +7875,7 @@ class A:
78757875
return 0
78767876

78777877
@to_same_callable
7878-
def g1() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
7878+
def g1() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
78797879

78807880
@to_same_callable
78817881
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.
79377937

79387938
class B:
79397939
@remove_first # E: Argument 1 to "remove_first" has incompatible type "Callable[[], int]"; expected "Callable[[T], int]"
7940-
def fn1() -> int: # E: Method must have at least one argument. Did you forget the "self" argument?
7940+
def fn1() -> int: # E: Method must have at least one parameter. Did you forget the "self" parameter?
79417941
return 0
79427942

79437943
@remove_first
7944-
def fn2(_x: int) -> int: # E: Method must have at least one argument. Did you forget the "self" argument?
7944+
def fn2(_x: int) -> int: # E: Method must have at least one parameter. Did you forget the "self" parameter?
79457945
return 0
79467946

79477947
@remove_first
@@ -8009,7 +8009,7 @@ def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]:
80098009

80108010
def unchecked():
80118011
class Bad:
8012-
def fn() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
8012+
def fn() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80138013
def fn2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self)
80148014

80158015
# TODO: would be nice to make this error, but now we see the func
@@ -8030,29 +8030,29 @@ def unchecked():
80308030

80318031
def checked() -> None:
80328032
class Bad:
8033-
def fn() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
8033+
def fn() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80348034
def fn2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self)
80358035

80368036
@to_same_callable
8037-
def g() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
8037+
def g() -> None: ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80388038
@to_same_callable
80398039
def g2(x: int) -> None: ... # E: "self" parameter missing for a non-static method (or an invalid type for self)
80408040

80418041
class AlsoBad:
8042-
def fn(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
8042+
def fn(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80438043
def fn2(x): ...
80448044

80458045
@to_same_callable
8046-
def g(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
8046+
def g(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80478047
@to_same_callable
80488048
def g2(x): ...
80498049

80508050
class Ok:
8051-
def fn(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
8051+
def fn(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80528052
def fn2(x): ...
80538053

80548054
@to_same_callable
8055-
def g(): ... # E: Method must have at least one argument. Did you forget the "self" argument?
8055+
def g(): ... # E: Method must have at least one parameter. Did you forget the "self" parameter?
80568056
@to_same_callable
80578057
def g2(x): ...
80588058
[builtins fixtures/tuple.pyi]

test-data/unit/check-functions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ class A:
27712771
@dec
27722772
def e(self) -> int: pass
27732773
@property
2774-
def g() -> int: pass # E: Method must have at least one argument. Did you forget the "self" argument?
2774+
def g() -> int: pass # E: Method must have at least one parameter. Did you forget the "self" parameter?
27752775
@property
27762776
def h(self, *args, **kwargs) -> int: pass # OK
27772777
[builtins fixtures/property.pyi]

test-data/unit/check-super.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class A:
375375
return 1
376376

377377
class B(A):
378-
def g() -> None: # E: Method must have at least one argument. Did you forget the "self" argument?
378+
def g() -> None: # E: Method must have at least one parameter. Did you forget the "self" parameter?
379379
super().f() # E: "super()" requires one or two positional arguments in enclosing function
380380
def h(self) -> None:
381381
def a() -> None:

test-data/unit/fine-grained.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,11 +1572,11 @@ class A:
15721572
[file b.py.3]
15731573
2
15741574
[out]
1575-
a.py:3: error: Method must have at least one argument. Did you forget the "self" argument?
1575+
a.py:3: error: Method must have at least one parameter. Did you forget the "self" parameter?
15761576
==
1577-
a.py:3: error: Method must have at least one argument. Did you forget the "self" argument?
1577+
a.py:3: error: Method must have at least one parameter. Did you forget the "self" parameter?
15781578
==
1579-
a.py:3: error: Method must have at least one argument. Did you forget the "self" argument?
1579+
a.py:3: error: Method must have at least one parameter. Did you forget the "self" parameter?
15801580

15811581
[case testBaseClassDeleted]
15821582
import m
@@ -1993,11 +1993,11 @@ class A:
19931993
class A:
19941994
def foo(self) -> int: pass
19951995
[out]
1996-
a.py:2: error: Method must have at least one argument. Did you forget the "self" argument?
1996+
a.py:2: error: Method must have at least one parameter. Did you forget the "self" parameter?
19971997
==
1998-
a.py:2: error: Method must have at least one argument. Did you forget the "self" argument?
1998+
a.py:2: error: Method must have at least one parameter. Did you forget the "self" parameter?
19991999
==
2000-
a.py:2: error: Method must have at least one argument. Did you forget the "self" argument?
2000+
a.py:2: error: Method must have at least one parameter. Did you forget the "self" parameter?
20012001
==
20022002

20032003
[case testPreviousErrorInMethodSemanal2]

0 commit comments

Comments
 (0)