Represent type-checked specifications as Python classes and incrementally build them.
Project description
Spec Classes
This is a small utility package that provides the spec_cls
decorator
that adds helper methods to allow users to mutate fields.
Installation
pip install spec-classes
Documentation
There is not much in the way of standalone documentation, but everything is documented fairly thoroughly in the source code, or you can install it and the view the inline documentation using:
>>> from spec_classes import spec_class
>>> help(spec_class)
A class decorator that adds `with_<field>`, `transform_<field>` and
`without_<field>` methods to a class in order to simplify the incremental
building and mutating of specification objects. By default these methods
return a new instance decorated class, with the appropriate field mutated.
...
Examples
@spec_class
class UnkeyedSpec:
nested_scalar: int = 1
nested_scalar2: str = 'original value'
@spec_class(key='key')
class KeyedSpec:
key: str = 'key'
nested_scalar: int = 1
nested_scalar2: str = 'original value'
@spec_class(key='key')
class Spec:
key: str = None
scalar: int = None
list_values: List[int] = None
dict_values: Dict[str, int] = None
set_values: Set[str] = None
spec: UnkeyedSpec = None
spec_list_items: List[UnkeyedSpec] = None
spec_dict_items: Dict[str, UnkeyedSpec] = None
keyed_spec_list_items: List[KeyedSpec] = None
keyed_spec_dict_items: Dict[str, KeyedSpec] = None
recursive: Spec = None
s = Spec()
spec.with_scalar(3).with_spec_list_item('x')....
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
spec-classes-0.3.3.tar.gz
(37.3 kB
view hashes)
Built Distribution
Close
Hashes for spec_classes-0.3.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7e31c91ff364c92c39975b133f50f42c9c6992294fed947ac73c7ba5bb815e7 |
|
MD5 | 7a19fdc6e56c3cb61c0ff46311201839 |
|
BLAKE2b-256 | c191340e9f313d63987292fc903da156834d244914b2deb177ae50351de45deb |