Skip to content

Use [arg-type] code for some one-off argument type error messages #9090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def invalid_keyword_var_arg(self, typ: Type, is_mapping: bool, context: Context)
suffix = ', not {}'.format(format_type(typ))
self.fail(
'Argument after ** must be a mapping{}'.format(suffix),
context)
context, code=codes.ARG_TYPE)

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

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

def type_arguments_not_allowed(self, context: Context) -> None:
self.fail('Parameterized generics cannot be used with class or instance checks', context)
Expand Down
23 changes: 23 additions & 0 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,26 @@ def f() -> Optional[C]:

f( # type: ignore[operator]
) + C()

[case testErrorCodeSpecialArgTypeErrors]
from typing import TypedDict

class C(TypedDict):
x: int

c: C
c.setdefault('x', '1') # type: ignore[arg-type]

class A:
pass

class B(A):
def f(self) -> None:
super(1, self).foo() # type: ignore[arg-type]

def f(**x: int) -> None:
pass

f(**1) # type: ignore[arg-type]
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]