TypeScript has a Pick type which can take an existing type and create a new one by picking individual attributes. I would like to have a similar functionality in Python, so for example:
from dataclasses import dataclass
from pick import Pick
@dataclasses.dataclass
class Foo:
x: int
y: float
z: str
Bar = Pick(Foo, ('x', 'y'))
foo = Foo(1, 2.0, '3')
bar = Bar(1, 2.0)
Run Code Online (Sandbox Code Playgroud)
I want this to avoid the problem of partial object population without having to explicitly define …