Metadata-Version: 2.1
Name: spec-classes
Version: 0.2.11
Summary: Represent type-checked specifications as Python classes and incrementally build them.
Home-page: https://github.com/matthewwardrop/spec-classes
Author: Matthew Wardrop
Author-email: mpwardrop@gmail.com
License: UNKNOWN
Keywords: spec-classes
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: inflect
Requires-Dist: lazy-object-proxy
Provides-Extra: test
Requires-Dist: flake8 ; extra == 'test'
Requires-Dist: flake8-docstrings (>=0.2.7) ; extra == 'test'
Requires-Dist: pydocstyle (==3.0.0) ; extra == 'test'
Requires-Dist: pyflakes ; extra == 'test'
Requires-Dist: pylint (==2.3.1) ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: pytest-coverage ; extra == 'test'
Requires-Dist: tox ; extra == 'test'

# 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

```shell
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:

```python
>>> 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

```python
@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')....
```

