dataclasses-xargs
An extension to the dataclasses library allowing you to push your unnamed parameters to a specific field.
Installation
pip3 install dataclasses-xargs
Usage Example
from dataclasses_xargs import dataclass
@dataclass
class FailTest(object):
a: int = None
b: str = None
c: list = None
@dataclass(xarg_field="c")
class SuccessTest(object):
a: int = None
b: str = None
c: list = None
# When xarg_field is not defined, dataclasses work as normal and will throw an error if you pass in double parameters
try:
FailTest(1, 2, 3, 4, 5, a=1, b="b")
except TypeError as e:
assert e.args[0] == "FailTest.__init__() got multiple values for argument 'a'"
# When defined, and the xarg_field is not passed as a named parameter, all unnamed parameters will be pushed to the xarg_field.
# Note that the xarg_field still needs to be defined in the class, see above.
dcl = SuccessTest(1, 2, 3, 4, 5, a=1, b="b")
print(dcl)
"""
SuccessTest(a=1, b='b', c=(1, 2, 3, 4, 5))
"""
assert dcl.a == 1
assert dcl.b == "b"
assert dcl.c == (1, 2, 3, 4, 5)
dcl = SuccessTest(1, 2, 3, 4, 5, a=1, b="b", c=[0, 0, 0])
print(dcl)
"""
SuccessTest(a=1, b='b', c=[0, 0, 0])
"""
assert dcl.a == 1
assert dcl.b == "b"
assert dcl.c == [0, 0, 0]
exit(0)
Metadata
Release files for dataclasses-xargs 1.0.2
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 |
|---|---|---|---|---|
| dataclasses_xargs-1.0.2.tar.gz | 19.9 kB | Without provenance | Details for dataclasses_xargs-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dataclasses_xargs-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for dataclasses_xargs-1.0.2-py3-none-any.whl |
Total release size: 39.9 kB
Release files / dataclasses_xargs-1.0.2.tar.gz
| Download URL | dataclasses_xargs-1.0.2.tar.gz |
|---|---|
| Size | 19.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d32a07afbe8368b47ab672572a391f3483e5d9c8ffa226cce41699bdc3070f4
|
|
BLAKE2b-256 checksum How to use checksums |
c21048897485316205da3feeae02348415513b1d73a8f5a4eb29fc21b851d456
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / dataclasses_xargs-1.0.2-py3-none-any.whl
| Download URL | dataclasses_xargs-1.0.2-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11e31dfad81faa477f2e26c3f63fafb0ed16ae47eace42800b6db280c91d86b5
|
|
BLAKE2b-256 checksum How to use checksums |
3bc808567c8e3113fba85aff30a35896c4951238d1d947641faaca4b4ca76102
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for dataclasses-xargs 1.0.2
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.