Skip to content

unpack dataclasses/types or subsets of them to act as typed dict  #12906

Closed as not planned
@RonnyPfannschmidt

Description

@RonnyPfannschmidt

Feature

often times helper methods take all the fields or subsets of the fields of a type/dataclass

in coordination with #4441

@dataclass
class MyModel:
   id: uuid
   name: str
   hostname: str
   memory_size: int

and i want to declare helpers like

# bad names
Magic = SubsetTypedDict(MyModel, exclude=["id"], total=False)

def wait_for_update(model_or_id: Model|uuid, **kw: Magic) -> Model:
   ...

** context **

spin out of #4441, based on my comment and the suggestion in

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions