Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow spreading of a TypedDict into another TypedDict #11108

Closed
r1chardj0n3s opened this issue Sep 14, 2021 · 2 comments
Closed

Allow spreading of a TypedDict into another TypedDict #11108

r1chardj0n3s opened this issue Sep 14, 2021 · 2 comments

Comments

@r1chardj0n3s
Copy link

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)

@graingert
Copy link
Contributor

graingert commented Jan 7, 2022

I'd like to be able to use this for typeddicts that extend each other eg

class Spam(TypedDict):
    one: str
    
class Ham(Spam):
    two: str

x = Spam(one='one')
y = Ham(**x, two="two")

@AlexWaygood
Copy link
Member

Closing as a duplicate of #9408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants