Skip to content

build a typeddict from another #10585

Closed
Closed
@dfroger

Description

@dfroger

I'm looking for a way to build a typeddict from another:

given:

class Foo(TypedDict):
    a: int
    b: int


class Bar(Foo):
    c: int


foo = Foo(a=1, b=2)

I would like to do bar = Bar(**foo, c=5), because we perform this operation many times with many dict and many keys, and bar = 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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions