scalarstop.dataclasses¶
A forked version of the Python dataclasses module.
Create a dataclass with the decorator @sp.dataclass as follows:
import scalarstop as sp
@sp.dataclass
class Hyperparams(sp.HyperparamsType):
val1: int
val2: str
The Python dataclasses module uses singletons to compare
certain values in internal code. This makes it difficult to
cloudpickle a dataclass and then unpickle it.
This version of the dataclasses module is better-designed
to be shared across different Python processes.
Module Contents¶
Functions¶
|
Returns True if the input is a Python dataclass. |
|
Forked verson of |
|
Forked verson of |
|
Forked verson of |
Attributes¶
- dataclass¶
- fields(class_or_instance: Any) Tuple[Any, Ellipsis]¶
Forked verson of
dataclasses.fields().Return a tuple describing the fields of this dataclass. Accepts a dataclass or an instance of one. Tuple elements are of type Field.
- asdict(obj: Any, *, dict_factory: type = dict) Dict[str, Any]¶
Forked verson of
dataclasses.asdict().Return the fields of a
dataclass()instance as a new tuple of field values.Example usage:
@dataclass class C: x: int y: int c = C(1, 2) assert asdict(c) == {'x': 1, 'y': 2}
If given,
dict_factorywill be used instead of built-indict.The function applies recursively to field values that are
dataclass()instances. This will also look into built-in containers:tuple,list, anddict.
- astuple(obj, *, tuple_factory=tuple) Tuple[Any, Ellipsis]¶
Forked verson of
dataclasses.astuple().Return the fields of a
dataclass()instance as a new tuple of field values.Example usage:
@dataclass class C: x: int y: int c = C(1, 2) assert astuple(c) == (1, 2)
If given,
tuple_factorywill be used instead of built-intuple.The function applies recursively to field values that are
dataclass()instances. This will also look into built-in containers:tuple,list, anddict.