Skip to content

Support Unpack with dict for keyword arguments: **kwargs: Unpack[dict[Literal["test"], ...]] #17241

Closed as not planned
@intgr

Description

@intgr

Bug Report

Mypy has support for declaring kwargs as **kwargs: Unpack[SomeTypedDict].

However, sometimes for dicts with uniform value types, it's more convenient to declare them in terms of dict[Literal["key", "another"], ...]. Other times it's a pragmatic work-around to the lack of support for @final declaration for TypedDict (#7981).

To Reproduce

This should pass mypy checking:

from typing import Literal, Unpack

def example(**kwargs: Unpack[dict[Literal["test"], int]]):
    #                        ^^^^
    pass

example(test=123)

Playground link

Actual Behavior

Rejected by mypy with the following error:

error: Unpack item in ** argument must be a TypedDict [misc]

Your Environment

  • Mypy version used: 1.10.0
  • Python version used: 3.12.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions