Skip to content

Commit f2a7dbd

Browse files
committed
add new error code with sub code of misc
1 parent 7a42fa5 commit f2a7dbd

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

mypy/errorcodes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ def __hash__(self) -> int:
287287
# This is a catch-all for remaining uncategorized errors.
288288
MISC: Final = ErrorCode("misc", "Miscellaneous other checks", "General")
289289

290+
CALL_ARG_MISC: Final = ErrorCode(
291+
"call-arg", "Check number, names and kinds of arguments in calls", "General", sub_code_of=MISC
292+
)
293+
# CALL_ARG_MISC reuses the "call-arg" code string, so keep CALL_ARG as the canonical
294+
# code that "call-arg" resolves to in the registry.
295+
error_codes[CALL_ARG.code] = CALL_ARG
296+
290297
OVERLOAD_CANNOT_MATCH: Final = ErrorCode(
291298
"overload-cannot-match",
292299
"Warn if an @overload signature can never be matched",

mypy/messages.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,9 @@ def too_many_positional_arguments(self, callee: CallableType, context: Context)
970970
msg = "Too many positional arguments"
971971
else:
972972
msg = "Too many positional arguments" + for_function(callee)
973-
self.fail(msg, context, code=codes.CALL_ARG)
973+
self.fail(msg, context, code=codes.CALL_ARG_MISC)
974974
self.maybe_note_about_special_args(callee, context)
975-
self.note_defined_here(callee, context)
975+
self.note_defined_here(callee, context, code=codes.CALL_ARG_MISC)
976976

977977
def maybe_note_about_special_args(self, callee: CallableType, context: Context) -> None:
978978
if self.prefer_simple_messages():
@@ -1019,7 +1019,9 @@ def unexpected_keyword_argument(
10191019
)
10201020
self.note_defined_here(callee, context)
10211021

1022-
def note_defined_here(self, callee: CallableType, context: Context) -> None:
1022+
def note_defined_here(
1023+
self, callee: CallableType, context: Context, code: ErrorCode = codes.CALL_ARG
1024+
) -> None:
10231025
module = find_defining_module(self.modules, callee)
10241026
if (
10251027
module
@@ -1032,7 +1034,7 @@ def note_defined_here(self, callee: CallableType, context: Context) -> None:
10321034
fname = "Called function"
10331035
else:
10341036
fname = fname.split(" of ")[0] # use short method names in the note
1035-
self.note(f'{fname} defined in "{module.fullname}"', context, code=codes.CALL_ARG)
1037+
self.note(f'{fname} defined in "{module.fullname}"', context, code=code)
10361038

10371039
def duplicate_argument_value(self, callee: CallableType, index: int, context: Context) -> None:
10381040
self.fail(

test-data/unit/check-errorcodes.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ def h(x: int, y: int, z: int) -> None: pass
331331
h(y=1, z=1) # E: Missing positional argument "x" in call to "h" [call-arg]
332332
h(y=1) # E: Missing positional arguments "x", "z" in call to "h" [call-arg]
333333

334+
[case testTooManyPositionalArgumentsErrorCode]
335+
def f(a: int, *, b: int) -> None: pass
336+
f(1, 2) # E: Too many positional arguments for "f" [call-arg]
337+
f(1, 2) # type: ignore[call-arg]
338+
f(1, 2) # type: ignore[misc]
339+
340+
[case testTooManyPositionalArgumentsCoveredByMiscUnused]
341+
# flags: --warn-unused-ignores
342+
def f(a: int, *, b: int) -> None: pass
343+
f(1, 2) # type: ignore[misc] # E: Unused "type: ignore" comment, use narrower [call-arg] instead of [misc] code [unused-ignore]
344+
334345
[case testErrorCodeArgType]
335346
def f(x: int) -> None: pass
336347
f('') # E: Argument 1 to "f" has incompatible type "str"; expected "int" [arg-type]

0 commit comments

Comments
 (0)