Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
58988cc
Update error message for missing argument type annotation
hyperkai Jan 31, 2026
416a76a
Update error messages for missing type annotations
hyperkai Jan 31, 2026
8c5d9cb
Fix type annotation error messages in tests
hyperkai Jan 31, 2026
d29c114
Fix type annotation error message in test
hyperkai Jan 31, 2026
a894621
Fix wording in error message for self parameter
hyperkai Feb 1, 2026
5343adb
Update check-classes.test
hyperkai Feb 1, 2026
a927084
Update check-selftype.test
hyperkai Feb 1, 2026
1a7ac4f
Update check-overloading.test
hyperkai Feb 1, 2026
f5551e0
Update message_registry.py
hyperkai Feb 1, 2026
62f2204
Update check-functions.test
hyperkai Feb 1, 2026
79f7b11
Update message_registry.py
hyperkai Feb 1, 2026
48c627c
Update check-fastparse.test
hyperkai Feb 1, 2026
f53a296
Update parse-errors.test
hyperkai Feb 1, 2026
9d0ae67
Update semanal-errors.test
hyperkai Feb 1, 2026
5458f4d
Update check-errorcodes.test
hyperkai Feb 1, 2026
5c8534b
Update message_registry.py
hyperkai Feb 1, 2026
8afa534
Update check-fastparse.test
hyperkai Feb 1, 2026
1755885
Update parse-errors.test
hyperkai Feb 1, 2026
47764f4
Update check-columns.test
hyperkai Feb 1, 2026
30dca1e
Update fine-grained.test
hyperkai Feb 1, 2026
6b9bde7
Update semanal-errors.test
hyperkai Feb 1, 2026
90e6954
Update check-functions.test
hyperkai Feb 1, 2026
4566bd1
Update check-errorcodes.test
hyperkai Feb 1, 2026
b9ab2a7
Update message_registry.py
hyperkai Feb 1, 2026
605c8b9
Update message_registry.py
hyperkai Feb 1, 2026
2d825fc
Update fastparse.py
hyperkai Feb 1, 2026
14ac318
Update fastparse.py
hyperkai Feb 1, 2026
24f8fba
Update checker.py
hyperkai Feb 1, 2026
cb7277a
Update message_registry.py
hyperkai Feb 1, 2026
6116842
Update message_registry.py
hyperkai Feb 1, 2026
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
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ def is_unannotated_any(t: Type) -> bool:
if is_unannotated_any(self.get_coroutine_return_type(ret_type)):
self.fail(message_registry.RETURN_TYPE_EXPECTED, fdef)
if any(is_unannotated_any(t) for t in fdef.type.arg_types):
self.fail(message_registry.ARGUMENT_TYPE_EXPECTED, fdef)
self.fail(message_registry.PARAM_TYPE_EXPECTED, fdef)

def check___new___signature(self, fdef: FuncDef, typ: CallableType) -> None:
self_type = fill_typevars_with_any(fdef.info)
Expand Down
6 changes: 3 additions & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,21 +1001,21 @@ def do_func_def(
if any(arg_types) or return_type:
if len(arg_types) != 1 and any(isinstance(t, EllipsisType) for t in arg_types):
self.fail(
message_registry.ELLIPSIS_WITH_OTHER_TYPEARGS,
message_registry.ELLIPSIS_WITH_OTHER_TYPEPARAMS,
lineno,
n.col_offset,
blocker=False,
)
elif len(arg_types) > len(arg_kinds):
self.fail(
message_registry.TYPE_SIGNATURE_TOO_MANY_ARGS,
message_registry.TYPE_SIGNATURE_TOO_MANY_PARAMS,
lineno,
n.col_offset,
blocker=False,
)
elif len(arg_types) < len(arg_kinds):
self.fail(
message_registry.TYPE_SIGNATURE_TOO_FEW_ARGS,
message_registry.TYPE_SIGNATURE_TOO_FEW_PARAMS,
lineno,
n.col_offset,
blocker=False,
Expand Down
18 changes: 9 additions & 9 deletions mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
RETURN_TYPE_EXPECTED: Final = ErrorMessage(
"Function is missing a return type annotation", codes.NO_UNTYPED_DEF
)
ARGUMENT_TYPE_EXPECTED: Final = ErrorMessage(
"Function is missing a type annotation for one or more arguments", codes.NO_UNTYPED_DEF
PARAM_TYPE_EXPECTED: Final = ErrorMessage(
"Function is missing a type annotation for one or more parameters", codes.NO_UNTYPED_DEF
)
KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPE: Final = ErrorMessage(
'Keyword argument only valid with "str" key type in call to "dict"'
Expand Down Expand Up @@ -224,7 +224,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:

# Self-type
MISSING_OR_INVALID_SELF_TYPE: Final = ErrorMessage(
"Self argument missing for a non-static method (or an invalid type for self)"
"self parameter missing for a non-static method (or an invalid type for self)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also changed Self to self which is actually used as a parameter because It's more understandable:

class Cls:  # ↓↓↓↓
   def method(self) -> None: ...

)
ERASED_SELF_TYPE_NOT_SUPERTYPE: Final = ErrorMessage(
'The erased type of self "{}" is not a supertype of its class "{}"'
Expand Down Expand Up @@ -308,14 +308,14 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
TYPE_COMMENT_SYNTAX_ERROR_VALUE: Final = ErrorMessage(
'Syntax error in type comment "{}"', codes.SYNTAX
)
ELLIPSIS_WITH_OTHER_TYPEARGS: Final = ErrorMessage(
"Ellipses cannot accompany other argument types in function type signature", codes.SYNTAX
ELLIPSIS_WITH_OTHER_TYPEPARAMS: Final = ErrorMessage(
"Ellipses cannot accompany other parameter types in function type signature", codes.SYNTAX
)
TYPE_SIGNATURE_TOO_MANY_ARGS: Final = ErrorMessage(
"Type signature has too many arguments", codes.SYNTAX
TYPE_SIGNATURE_TOO_MANY_PARAMS: Final = ErrorMessage(
"Type signature has too many parameters", codes.SYNTAX
)
TYPE_SIGNATURE_TOO_FEW_ARGS: Final = ErrorMessage(
"Type signature has too few arguments", codes.SYNTAX
TYPE_SIGNATURE_TOO_FEW_PARAMS: Final = ErrorMessage(
"Type signature has too few parameters", codes.SYNTAX
)
ARG_CONSTRUCTOR_NAME_EXPECTED: Final = ErrorMessage("Expected arg constructor name", codes.SYNTAX)
ARG_CONSTRUCTOR_TOO_MANY_ARGS: Final = ErrorMessage(
Expand Down
20 changes: 10 additions & 10 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -7836,7 +7836,7 @@ def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]:
class A:
def undecorated() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?

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

def undecorated_not_self_2(self: int) -> None: ... # E: The erased type of self "builtins.int" is not a supertype of its class "__main__.A"

Expand Down Expand Up @@ -7864,7 +7864,7 @@ class A:
def g1() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?

@to_same_callable
def g2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)
def g2(x: int) -> None: ... # E: self parameter missing for a non-static method (or an invalid type for self)

@to_same_callable
def g3(self: int) -> None: ... # E: The erased type of self "builtins.int" is not a supertype of its class "__main__.A"
Expand Down Expand Up @@ -7909,7 +7909,7 @@ class A:
return 0

@to_same_callable
def fn2(_x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
def fn2(_x: int) -> int: # E: self parameter missing for a non-static method (or an invalid type for self)
return 0

@to_same_callable
Expand All @@ -7931,7 +7931,7 @@ class B:
return 0

@remove_first
def fn3(self, _x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
def fn3(self, _x: int) -> int: # E: self parameter missing for a non-static method (or an invalid type for self)
return 0

@remove_first
Expand Down Expand Up @@ -7965,15 +7965,15 @@ reveal_type(C().fn3) # N: Revealed type is "def (self: __main__.C, _x: builtins

class D:
@add_wrong_first
def fn1() -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
def fn1() -> int: # E: self parameter missing for a non-static method (or an invalid type for self)
return 0

@add_wrong_first
def fn2(_x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
def fn2(_x: int) -> int: # E: self parameter missing for a non-static method (or an invalid type for self)
return 0

@add_wrong_first
def fn3(self, _x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
def fn3(self, _x: int) -> int: # E: self parameter missing for a non-static method (or an invalid type for self)
return 0

reveal_type(D().fn1) # E: Invalid self argument "D" to attribute function "fn1" with type "Callable[[int], int]" \
Expand All @@ -7996,7 +7996,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 fn2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)
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
# being decorated as Any, not as a callable
Expand All @@ -8017,12 +8017,12 @@ 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 fn2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)
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?
@to_same_callable
def g2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)
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?
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ x = cast(int, y) # E:5: Redundant cast to "int"

[case testColumnTypeSignatureHasTooFewArguments]
if int():
def f(x, y): # E:5: Type signature has too few arguments
def f(x, y): # E:5: Type signature has too few parameters
# type: (int) -> None
pass

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ main:1: error: Invalid syntax [syntax]
main:1: error: Invalid syntax. Perhaps you forgot a comma? [syntax]

[case testErrorCodeSyntaxError2]
def f(): # E: Type signature has too many arguments [syntax]
def f(): # E: Type signature has too many parameters [syntax]
# type: (int) -> None
1

Expand Down Expand Up @@ -382,7 +382,7 @@ def f(x): # E: Function is missing a type annotation [no-untyped-def]
def g(x: int): # E: Function is missing a return type annotation [no-untyped-def]
pass

def h(x) -> None: # E: Function is missing a type annotation for one or more arguments [no-untyped-def]
def h(x) -> None: # E: Function is missing a type annotation for one or more parameters [no-untyped-def]
pass

def gen(): # E: Function is missing a return type annotation [no-untyped-def]
Expand Down Expand Up @@ -545,11 +545,11 @@ from typing import cast
x = cast(int, int()) # E: Redundant cast to "int" [redundant-cast]

[case testErrorCodeInvalidCommentSignature]
def f(x): # E: Type signature has too few arguments [syntax]
def f(x): # E: Type signature has too few parameters [syntax]
# type: () -> None
pass

def g(x): # E: Type signature has too many arguments [syntax]
def g(x): # E: Type signature has too many parameters [syntax]
# type: (int, int) -> None
pass

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-fastparse.test
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ def f(*,
[out]

[case testFasterParseTooManyArgumentsAnnotation]
def f(): # E: Type signature has too many arguments
def f(): # E: Type signature has too many parameters
# type: (int) -> None
pass

f()
f(1) # E: Too many arguments for "f"

[case testFasterParseTooFewArgumentsAnnotation]
def f(x, y): # E: Type signature has too few arguments
def f(x, y): # E: Type signature has too few parameters
# type: (int) -> None
x()
y()
Expand Down Expand Up @@ -215,10 +215,10 @@ x @ 1
x @= 1

[case testFastParserShowsMultipleErrors]
def f(x): # E: Type signature has too few arguments
def f(x): # E: Type signature has too few parameters
# type: () -> None
pass
def g(): # E: Type signature has too many arguments
def g(): # E: Type signature has too many parameters
# type: (int) -> None
pass

Expand Down
14 changes: 7 additions & 7 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ main:2: error: Function is missing a type annotation
# flags: --disallow-untyped-defs
def f(x) -> int: pass
[out]
main:2: error: Function is missing a type annotation for one or more arguments
main:2: error: Function is missing a type annotation for one or more parameters

[case testNoArgumentFunction]
# flags: --disallow-untyped-defs
Expand Down Expand Up @@ -63,7 +63,7 @@ async def f(): # E: Function is missing a return type annotation \

[case testAsyncUnannotatedArgument]
# flags: --disallow-untyped-defs
async def f(x) -> None: # E: Function is missing a type annotation for one or more arguments
async def f(x) -> None: # E: Function is missing a type annotation for one or more parameters
pass
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]
Expand Down Expand Up @@ -830,7 +830,7 @@ import standard, incomplete
def incomplete(x) -> int:
return 0
[file incomplete.py]
def incomplete(x) -> int: # E: Function is missing a type annotation for one or more arguments
def incomplete(x) -> int: # E: Function is missing a type annotation for one or more parameters
return 0
[file mypy.ini]
\[mypy]
Expand All @@ -847,7 +847,7 @@ import standard, incomplete
def incomplete(x) -> int:
return 0
[file incomplete.py]
def incomplete(x) -> int: # E: Function is missing a type annotation for one or more arguments
def incomplete(x) -> int: # E: Function is missing a type annotation for one or more parameters
return 0
[file pyproject.toml]
\[tool.mypy]
Expand Down Expand Up @@ -1555,7 +1555,7 @@ def g(m: Movie) -> Movie:

def f(i: int): # E: Function is missing a return type annotation
pass
def g(i) -> None: # E: Function is missing a type annotation for one or more arguments
def g(i) -> None: # E: Function is missing a type annotation for one or more parameters
pass
def h(i: int) -> int: # no error
return i
Expand All @@ -1582,7 +1582,7 @@ def f(i: int, s):

[out]
main:3: error: Function is missing a return type annotation
main:3: error: Function is missing a type annotation for one or more arguments
main:3: error: Function is missing a type annotation for one or more parameters

[case testDisallowIncompleteDefsAttrsNoAnnotations]
# flags: --disallow-incomplete-defs
Expand All @@ -1609,7 +1609,7 @@ class Annotated:
import attrs

@attrs.define
class PartiallyAnnotated: # E: Function is missing a type annotation for one or more arguments
class PartiallyAnnotated: # E: Function is missing a type annotation for one or more parameters
bar: int = attrs.field()
baz = attrs.field()

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ main:8: error: Argument 1 to "g" has incompatible type "A"; expected "int"
class A:
def f(self):
# type: () -> None
def g(x): # E: Type signature has too few arguments
def g(x): # E: Type signature has too few parameters
# type: () -> None
pass

Expand All @@ -802,7 +802,7 @@ class A:
class B:
def g(self):
# type: () -> None
def h(x): # E: Type signature has too few arguments
def h(x): # E: Type signature has too few parameters
# type: () -> None
pass

Expand Down Expand Up @@ -2143,13 +2143,13 @@ class A:
def f(x, y, z): # type: (..., int) -> None
pass
[out]
main:1: error: Ellipses cannot accompany other argument types in function type signature
main:1: error: Ellipses cannot accompany other parameter types in function type signature

[case testEllipsisWithSomethingBeforeItFails]
def f(x, y, z): # type: (int, ...) -> None
pass
[out]
main:1: error: Ellipses cannot accompany other argument types in function type signature
main:1: error: Ellipses cannot accompany other parameter types in function type signature

[case testRejectCovariantArgument]
from typing import TypeVar, Generic
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -4347,7 +4347,7 @@ class Wrapper2:
@staticmethod
def foo(x: int) -> int: ...
@overload
def foo(x: str) -> str: ... # E: Self argument missing for a non-static method (or an invalid type for self)
def foo(x: str) -> str: ... # E: self parameter missing for a non-static method (or an invalid type for self)
@staticmethod
def foo(x): pass

Expand All @@ -4358,7 +4358,7 @@ class Wrapper3:
@overload
@staticmethod
def foo(x: str) -> str: ...
def foo(x: Union[int, str]): pass # E: Self argument missing for a non-static method (or an invalid type for self)
def foo(x: Union[int, str]): pass # E: self parameter missing for a non-static method (or an invalid type for self)
[builtins fixtures/staticmethod.pyi]

[case testOverloadWithSwappedDecorators2]
Expand Down Expand Up @@ -4394,7 +4394,7 @@ class Wrapper3:
def foo(x: int) -> int: ...

@overload
def foo(x: str) -> str: ... # E: Self argument missing for a non-static method (or an invalid type for self)
def foo(x: str) -> str: ... # E: self parameter missing for a non-static method (or an invalid type for self)

@staticmethod
def foo(x): pass
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-python38.test
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def g(x: int): ...

[case testPEP570ArgTypesMissing]
# flags: --disallow-untyped-defs
def f(arg, /) -> None: ... # E: Function is missing a type annotation for one or more arguments
def f(arg, /) -> None: ... # E: Function is missing a type annotation for one or more parameters

[case testPEP570ArgTypesBadDefault]
def f(arg: int = "ERROR", /) -> None: ... # E: Incompatible default for argument "arg" (default has type "str", argument has type "int")
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-selftype.test
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ class A:
def f(x: int) -> None: ...
def g(self: None) -> None: ...
[out]
main:3: error: Self argument missing for a non-static method (or an invalid type for self)
main:3: error: self parameter missing for a non-static method (or an invalid type for self)
main:4: error: The erased type of self "None" is not a supertype of its class "__main__.A"

[case testUnionPropertyField]
Expand Down
18 changes: 9 additions & 9 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -9124,15 +9124,15 @@ x = ''
x = 1

[out]
c.py:1: error: Type signature has too few arguments
a.py:1: error: Type signature has too few arguments
a.py:5: error: Type signature has too few arguments
a.py:11: error: Type signature has too few arguments
==
c.py:1: error: Type signature has too few arguments
a.py:1: error: Type signature has too few arguments
a.py:5: error: Type signature has too few arguments
a.py:11: error: Type signature has too few arguments
c.py:1: error: Type signature has too few parameters
a.py:1: error: Type signature has too few parameters
a.py:5: error: Type signature has too few parameters
a.py:11: error: Type signature has too few parameters
==
c.py:1: error: Type signature has too few parameters
a.py:1: error: Type signature has too few parameters
a.py:5: error: Type signature has too few parameters
a.py:11: error: Type signature has too few parameters

[case testErrorReportingNewAnalyzer]
# flags: --disallow-any-generics
Expand Down
Loading