Skip to content

Allow spreading of a TypedDict into another TypedDict #11108

Closed
@r1chardj0n3s

Description

@r1chardj0n3s

Feature

Currently TypedDict type checking rejects spread keyword arguments as a type violation, even when a TypedDict is provided as the spread source. Typing information is available and the spread operation works at runtime, so the error received is ... misleading at best, but also I think the spread should be possible, leveraging the typing from the source TypedDict.

Pitch

I would like to be able to do this (a simplified version of what I really want to do, which involves much larger typed dicts):

class Spam(TypedDict):
    one: str

x = Spam(one='one')
Spam(**x)

This currently results in this error from mypy:

x.py:5: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor  [misc]

(note that the code executes successfully because the spread does work)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions