Skip to content

Commit a08bbbb

Browse files
authored
Use [arg-type] code for some one-off argument type error messages (#9090)
Fixes #9083.
1 parent a04bdbf commit a08bbbb

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

mypy/messages.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ def invalid_keyword_var_arg(self, typ: Type, is_mapping: bool, context: Context)
854854
suffix = ', not {}'.format(format_type(typ))
855855
self.fail(
856856
'Argument after ** must be a mapping{}'.format(suffix),
857-
context)
857+
context, code=codes.ARG_TYPE)
858858

859859
def undefined_in_superclass(self, member: str, context: Context) -> None:
860860
self.fail('"{}" undefined in superclass'.format(member), context)
@@ -867,7 +867,8 @@ def first_argument_for_super_must_be_type(self, actual: Type, context: Context)
867867
type_str = 'a non-type instance'
868868
else:
869869
type_str = format_type(actual)
870-
self.fail('Argument 1 for "super" must be a type object; got {}'.format(type_str), context)
870+
self.fail('Argument 1 for "super" must be a type object; got {}'.format(type_str), context,
871+
code=codes.ARG_TYPE)
871872

872873
def too_few_string_formatting_arguments(self, context: Context) -> None:
873874
self.fail('Not enough arguments for format string', context,
@@ -1188,7 +1189,8 @@ def typeddict_setdefault_arguments_inconsistent(
11881189
expected: Type,
11891190
context: Context) -> None:
11901191
msg = 'Argument 2 to "setdefault" of "TypedDict" has incompatible type {}; expected {}'
1191-
self.fail(msg.format(format_type(default), format_type(expected)), context)
1192+
self.fail(msg.format(format_type(default), format_type(expected)), context,
1193+
code=codes.ARG_TYPE)
11921194

11931195
def type_arguments_not_allowed(self, context: Context) -> None:
11941196
self.fail('Parameterized generics cannot be used with class or instance checks', context)

test-data/unit/check-errorcodes.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,26 @@ def f() -> Optional[C]:
748748

749749
f( # type: ignore[operator]
750750
) + C()
751+
752+
[case testErrorCodeSpecialArgTypeErrors]
753+
from typing import TypedDict
754+
755+
class C(TypedDict):
756+
x: int
757+
758+
c: C
759+
c.setdefault('x', '1') # type: ignore[arg-type]
760+
761+
class A:
762+
pass
763+
764+
class B(A):
765+
def f(self) -> None:
766+
super(1, self).foo() # type: ignore[arg-type]
767+
768+
def f(**x: int) -> None:
769+
pass
770+
771+
f(**1) # type: ignore[arg-type]
772+
[builtins fixtures/dict.pyi]
773+
[typing fixtures/typing-typeddict.pyi]

0 commit comments

Comments
 (0)