@@ -3180,21 +3180,51 @@ stringified(a=1)
31803180Only string-keyed mappings can be unpacked into named keyword parameters.
31813181
31823182``` py
3183- def takes_name (* , name : str ) -> None : ...
3183+ from typing_extensions import TypedDict, Unpack
3184+
3185+ class HasNameKwargs (TypedDict ):
3186+ name: str
3187+
3188+ def takes_name_kwargs (** kwargs : Unpack[HasNameKwargs]) -> None : ...
31843189def _ (int_key_dict : dict[int , str ]) -> None :
31853190 # snapshot: invalid-argument-type
3186- takes_name (** int_key_dict)
3191+ takes_name_kwargs (** int_key_dict)
31873192```
31883193
31893194``` snapshot
31903195error[invalid-argument-type]: Argument expression after ** must be a mapping with `str` key type
3191- --> src/mdtest_snippet.py:4:16
3196+ --> src/mdtest_snippet.py:9:23
31923197 |
3193- 4 | takes_name (**int_key_dict)
3194- | ^^^^^^^^^^^^^^ Found `int`
3198+ 9 | takes_name_kwargs (**int_key_dict)
3199+ | ^^^^^^^^^^^^^^ Found `int`
31953200 |
31963201```
31973202
3203+ ### Non-mapping values are rejected without missing-argument cascades
3204+
3205+ ``` py
3206+ from typing_extensions import TypedDict, Unpack
3207+
3208+ class HasNameKwargs (TypedDict ):
3209+ name: str
3210+
3211+ class NotAMapping : ...
3212+
3213+ def takes_name_kwargs (** kwargs : Unpack[HasNameKwargs]) -> None : ...
3214+ def _ (bad : NotAMapping) -> None :
3215+ # snapshot: invalid-argument-type
3216+ takes_name_kwargs(** bad)
3217+ ```
3218+
3219+ ``` snapshot
3220+ error[invalid-argument-type]: Argument expression after ** must be a mapping type
3221+ --> src/mdtest_snippet.py:11:25
3222+ |
3223+ 11 | takes_name_kwargs(**bad)
3224+ | ^^^ Found `NotAMapping`
3225+ |
3226+ ```
3227+
31983228### Explicit keywords still conflict with maybe-present unpacked keys
31993229
32003230If a partial ` TypedDict ` may provide a key, passing that key explicitly still counts as a duplicate.
0 commit comments