lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
399 stars 49 forks source link

Partials - Dynamic Config Dataclasses for arbitrary callables #156

Closed lebrice closed 1 year ago

lebrice commented 2 years ago

This PR adds Partials: Dynamically created dataclasses for arbitrary callables.

It's still a work in progress. I'll update this whenever I find the time.

JesseFarebro commented 1 year ago

It would be good to add a test case to make sure Partial works with #223. For example,

@dataclasses.dataclass(frozen=True, kw_only=True)
class A:
    x: int
    y: bool = True

A1: Type[Partial[A]] = sp.config(A, ignore="x")

@dataclasses.dataclass(frozen=True, kw_only=True)
class B:
    a: Partial[A] = sp.subgroups({
        'a1': A1(y=False),
    })

b = sp.parse(B)

assert b.a(x=1) == A(x=1, y=False)