-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
build a typeddict from another #10585
Comments
can i work on this? |
(Regardless of the TypedDict stuff, I think mypy just currently doesn't have any support for inferring the keys contained in a **kwargs splat.) |
So I think I will use a cast. The scope of the dangerous code (ie, not type checked) is limited, it's flexible and not verbose, so it's not so bad. foo = Foo(a=1, b=2)
# dangerous code (not type checked): developper must ensure the missing keys are added
foo = cast(Bar, foo)
foo["c"] = 1
# end of dangerous code |
Adding this kind of code to the above snippet could be useful to remember to update the dangerous code when assert Bar.__annotations__ == {**Foo.__annotations__, "c": int} Wonder if this assertion could be done statically? |
Duplicate of #9408 |
I'm looking for a way to build a typeddict from another:
given:
I would like to do
bar = Bar(**foo, c=5)
, because we perform this operation many times with many dict and many keys, andbar = Bar(a=foo["a"], b=foo["b"], c=3)
would be really too verbose.I fear this is not possible yet. Any chance that such a functionality could be implemented?
I don't see a better workaround than
bar = Bar(**foo, c=5) # type: ignore
, maybe I'm missing something?Thanks!
The text was updated successfully, but these errors were encountered: