From 4f0dec383b4b9af60d4158dbf9968d14d71edf54 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 00:27:45 +0900 Subject: [PATCH 1/4] Update error message for unpacking TypedDict --- mypy/semanal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 17176e921051..f38a71cb16e3 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -1104,7 +1104,7 @@ def remove_unpack_kwargs(self, defn: FuncDef, typ: CallableType) -> CallableType return typ p_last_type = get_proper_type(last_type.type) if not isinstance(p_last_type, TypedDictType): - self.fail("Unpack item in ** argument must be a TypedDict", last_type) + self.fail("Unpack item in ** parameter must be a TypedDict", last_type) new_arg_types = typ.arg_types[:-1] + [AnyType(TypeOfAny.from_error)] return typ.copy_modified(arg_types=new_arg_types) overlap = set(typ.arg_names) & set(p_last_type.items) From 5ffe6064c5477a0909631bfe71c97ec7489ae6ba Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 00:32:01 +0900 Subject: [PATCH 2/4] Fix comment for Unpack usage in foo function --- test-data/unit/check-varargs.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 704cdb6617ee..4f45e61a6b6e 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -792,7 +792,7 @@ def baz(**kwargs: Unpack[Person]) -> None: # OK [case testUnpackWithoutTypedDict] from typing_extensions import Unpack -def foo(**kwargs: Unpack[dict]) -> None: # E: Unpack item in ** argument must be a TypedDict +def foo(**kwargs: Unpack[dict]) -> None: # E: Unpack item in ** parameter must be a TypedDict ... [builtins fixtures/dict.pyi] From d851c88004cbf07bd43ad0da6b8b811674da544b Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 00:34:38 +0900 Subject: [PATCH 3/4] Fix unpacking error in kwargs for bad functions --- test-data/unit/check-typevar-tuple.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-typevar-tuple.test b/test-data/unit/check-typevar-tuple.test index 0b7f8fe06749..874c79df0e19 100644 --- a/test-data/unit/check-typevar-tuple.test +++ b/test-data/unit/check-typevar-tuple.test @@ -2191,7 +2191,7 @@ g(1, 2, 3) # E: Missing named argument "a" for "g" \ def bad( *args: Unpack[Keywords], # E: "Keywords" cannot be unpacked (must be tuple or TypeVarTuple) - **kwargs: Unpack[Ints], # E: Unpack item in ** argument must be a TypedDict + **kwargs: Unpack[Ints], # E: Unpack item in ** parameter must be a TypedDict ) -> None: ... reveal_type(bad) # N: Revealed type is "def (*args: Any, **kwargs: Any)" @@ -2199,7 +2199,7 @@ def bad2( one: int, *args: Unpack[Keywords], # E: "Keywords" cannot be unpacked (must be tuple or TypeVarTuple) other: str = "no", - **kwargs: Unpack[Ints], # E: Unpack item in ** argument must be a TypedDict + **kwargs: Unpack[Ints], # E: Unpack item in ** parameter must be a TypedDict ) -> None: ... reveal_type(bad2) # N: Revealed type is "def (one: builtins.int, *args: Any, other: builtins.str =, **kwargs: Any)" [builtins fixtures/dict.pyi] From c527aea283184c26829470165cdfbc7331aa37d1 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 00:37:37 +0900 Subject: [PATCH 4/4] Fix error message in bad_kwargs function definition --- test-data/unit/semanal-errors.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/semanal-errors.test b/test-data/unit/semanal-errors.test index 2526d633fbb8..b69d35ce030e 100644 --- a/test-data/unit/semanal-errors.test +++ b/test-data/unit/semanal-errors.test @@ -1471,7 +1471,7 @@ class Variadic(Generic[Unpack[TVariadic], Unpack[TVariadic2]]): # E: Can only u def bad_args(*args: TVariadic): # E: TypeVarTuple "TVariadic" is only valid with an unpack pass -def bad_kwargs(**kwargs: Unpack[TVariadic]): # E: Unpack item in ** argument must be a TypedDict +def bad_kwargs(**kwargs: Unpack[TVariadic]): # E: Unpack item in ** parameter must be a TypedDict pass [builtins fixtures/dict.pyi]