quantlab.core.component.component#
- quantlab.core.component.component(*, many=False, **field_kwargs)[source]#
Declare a config dataclass field as holding a component, or several.
Use it in place of
dataclasses.fieldon a config dataclass. Withmany=Falsethe field holds one component (orNone); withmany=Trueit holds a list or tuple of components, or a dict mapping names to components.config_to_dictandComponent.from_configwalk exactly the fields declared this way.- Parameters:
- manybool, default False
Whether the field holds a collection of components rather than one.
- **field_kwargs
Passed to
dataclasses.field(default,default_factory,kw_only…).
- Returns:
- dataclasses.Field
The field, its metadata marking it as a component field.
Examples
>>> import dataclasses >>> @dataclasses.dataclass(frozen=True) ... class PairConfig: ... first: object = component() ... rest: tuple = component(many=True, default=()) >>> component_fields(PairConfig) {'first': False, 'rest': True}