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.2.12.tar.gz
(32.8 kB
view hashes)
Built Distribution
Close
Hashes for spec_classes-0.2.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23c428b38fe88f9720214eea093d01070d985afe9170141c76b5f8d782680595 |
|
MD5 | c9603bce9d1723864af45a22a20a5525 |
|
BLAKE2b-256 | 1606f35740c3f8a4c59f03fb374e9b30bca8c9f0396db950cfe07778e93f692c |