rx-dataclasses
type verification and convert
from typing import *
from rx.operators import map as rxmap
from rxdata import dataclass, field, operators
@rxmap
def try_convert(n):
return int(n) if isinstance(n, str) and n.isalpha() else n
@dataclass
class Data:
# only int.
number: int = field(default=1,
invoke=operators.typeguard())
# only int or string convertable to int. Always results in int.
convert_or_die: Union[int] = field(default=1,
invoke=[try_convert,
operators.typeguard()])
# If is string and convertable to int - perform conversion. `typing.Any` type defined explicitly during `invoke` (just for example).
convert_or_accept: Union[int, str] = field(default=1,
invoke=[try_convert,
operators.typeguard(Any)])
> data = Data(None)
TypeError: type of number must be int; got NoneType instead
> data = Data(convert_or_die=None)
TypeError: type of convert_or_die must be int; got NoneType instead
> Data(convert_or_accept=None)
Data(number=1, convert_or_die=1, convert_or_accept=None)
data = Data()
data.number = '3'
> TypeError: type of number must be int; got str instead
data.number = 2
> Data(number=2, convert_or_die=1, convert_or_accept=1)
data.convert_or_die = 2
> Data(number=2, convert_or_die=2, convert_or_accept=1)
data.convert_or_accept = '3'
> Data(number=2, convert_or_die=2, convert_or_accept=3)
data.convert_or_accept = '3s'
> Data(number=2, convert_or_die=2, convert_or_accept='3s')
data.convert_or_accept = type
> Data(number=2, convert_or_die=2, convert_or_accept=<class 'type'>)
description
reactive python3 dataclasses - with attrs-like behaviour
- implicit and explicit typing verification during both
initand/orsetattr - customize preprocessing (convert) during both
initand/orsetattr - reactive attributes
install
> pip3 install rx-dataclasses
Metadata
Release files for rx-dataclasses 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rx-dataclasses-0.0.4.tar.gz | 18.2 kB | Without provenance | Details for rx-dataclasses-0.0.4.tar.gz |
Release files / rx-dataclasses-0.0.4.tar.gz
| Download URL | rx-dataclasses-0.0.4.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e84cb066b0aa4bd6b2e75c8f2b35c1c03977ae018ef41fc8158595424e767cc
|
|
BLAKE2b-256 checksum How to use checksums |
840b5533bd82be30e6ed9d904dcff8a85cf61bbadebeeba5dfb636e16cd8c463
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5
|
Security for rx-dataclasses 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.