Skip to content

Change error message for incompatible type assignment when using Generics #12556

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,14 +1511,16 @@ def check_argument_types(self,
mapper = ArgTypeExpander(self.argument_infer_context())
for i, actuals in enumerate(formal_to_actual):
for actual in actuals:

actual_type = arg_types[actual]
if actual_type is None:
continue # Some kind of error was already reported.
actual_kind = arg_kinds[actual]
# Check that a *arg is valid as varargs.
if (actual_kind == nodes.ARG_STAR and
not self.is_valid_var_arg(actual_type)):
not self.is_valid_var_arg(actual_type)):
messages.invalid_var_arg(actual_type, context)

if (actual_kind == nodes.ARG_STAR2 and
not self.is_valid_keyword_var_arg(actual_type)):
is_mapping = is_subtype(actual_type, self.chk.named_type('typing.Mapping'))
Expand Down
6 changes: 3 additions & 3 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ def incompatible_argument(self,
outer_context.index.value, quote_type_string(arg_type_str),
quote_type_string(expected_type_str))
else:
msg = 'Argument {} {}has incompatible type {}; expected {}'.format(
arg_label, target, quote_type_string(arg_type_str),
quote_type_string(expected_type_str))
msg = 'expression has type {}, variable has type {}'.format(
quote_type_string(arg_type_str), quote_type_string(expected_type_str))

object_type = get_proper_type(object_type)
if isinstance(object_type, TypedDictType):
code = codes.TYPEDDICT_ITEM
Expand Down
5 changes: 2 additions & 3 deletions test-data/unit/check-varargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,10 @@ if int():
b, b = f(b, b, *aa) # E: Argument 3 to "f" has incompatible type "*List[A]"; expected "B"
if int():
a, b = f(a, *a) # E: List or tuple expected as variable arguments
if int():
a, b = f(*a) # E: List or tuple expected as variable arguments

if int():
a, a = f(*aa)
if int():
a, b = f(*a) # E: List or tuple expected as variable arguments
if int():
b, a = f(b, *aa)
if int():
Expand Down