diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 603acbe84f0f..8223ccfe4ca0 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -2684,9 +2684,12 @@ def check_arg( context=context, outer_context=outer_context, ) - self.msg.incompatible_argument_note( - original_caller_type, callee_type, context, parent_error=error - ) + if not caller_kind.is_star(): + # For *args and **kwargs this note would be incorrect - we're comparing + # iterable/mapping type with union of relevant arg types. + self.msg.incompatible_argument_note( + original_caller_type, callee_type, context, parent_error=error + ) if not self.msg.prefer_simple_messages(): self.chk.check_possible_missing_await( caller_type, callee_type, context, error.code diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index ceb7af433dce..07cfd09b2529 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -3694,3 +3694,19 @@ def defer() -> int: ... [out] main: note: In function "a": main:6: error: Unsupported operand types for + ("int" and "str") + +[case testNoExtraNoteForUnpacking] +from typing import Protocol + +class P(Protocol): + arg: int + # Something that list and dict also have + def __contains__(self, item: object) -> bool: ... + +def foo(x: P, y: P) -> None: ... + +args: list[object] +foo(*args) # E: Argument 1 to "foo" has incompatible type "*list[object]"; expected "P" +kwargs: dict[str, object] +foo(**kwargs) # E: Argument 1 to "foo" has incompatible type "**dict[str, object]"; expected "P" +[builtins fixtures/dict.pyi]