Skip to main content

ctorrepr

https://img.shields.io/pypi/v/ctorrepr.svg https://img.shields.io/travis/astralblue/ctorrepr.svg Documentation Status Updates

A mix-in that provides __repr__() from constructor arguments.

Usage

To use, simply inherit from ~ctorrepr.CtorRepr then implement its ~ctorrepr.CtorRepr._collect_repr_args() to match your existing __init__() method:

>>> from ctorrepr import CtorRepr
>>> class X(CtorRepr):
...     def __init__(self, x1='x1', x2='x2', *poargs, **kwargs):
...         super().__init__(*poargs, **kwargs)
...         self.x1 = x1
...         self.x2 = x2
...     def _collect_repr_args(self, poargs, kwargs):
...         super()._collect_repr_args(poargs, kwargs)
...         poargs[:0] = self.x1, self.x2
>>> class Y(CtorRepr):
...     def __init__(self, *y, **kwargs):
...         super().__init__(**kwargs)
...         self.y = y          # completely consumes positional args
...     def _collect_repr_args(self, poargs, kwargs):
...         super()._collect_repr_args(poargs, kwargs)
...         poargs[:0] = self.y
>>> class Z(CtorRepr):
...     def __init__(self, *poargs, zk='zk', **kwargs):
...         super().__init__(*poargs, **kwargs)
...         self.zk = zk
...     def _collect_repr_args(self, poargs, kwargs):
...         super()._collect_repr_args(poargs, kwargs)
...         kwargs.update(zk=self.zk)
>>> class W(X, Y, Z):
...     def __str__(self):
...         return repr(self)
>>> print(' '.join(t.__name__ for t in W.mro()))
W X Y Z CtorRepr object
>>> print(W())
W('x1', 'x2', zk='zk')
>>> print(W(24))
W(24, 'x2', zk='zk')
>>> w = W(24, 25, 'y1', 'y2')
>>> w.y
('y1', 'y2')
>>> print(w)
W(24, 25, 'y1', 'y2', zk='zk')
>>> print(W(zk=100))
W('x1', 'x2', zk=100)

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2017-07-31)

  • First release on PyPI.

Metadata

Release files for ctorrepr 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ctorrepr 0.1.2
File Size Uploaded Provenance
ctorrepr-0.1.2.tar.gz 11.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ctorrepr 0.1.2
File Interpreter ABI Platform
ctorrepr-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 16.1 kB

Release files / ctorrepr-0.1.2.tar.gz

Download URL ctorrepr-0.1.2.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5bde58f3b531751ae8b9823b84540ef6df0b2c6f94ad4b212de4cbb2fb32c1f7
BLAKE2b-256 checksum
How to use checksums
05e89e57bc01bfde3f14b64378df6dda605cf45187f57756fef1b0147484f203
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / ctorrepr-0.1.2-py2.py3-none-any.whl

Download URL ctorrepr-0.1.2-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
024a77115c05283e7629216e687276cefd68ba1cba6352c2cf23280e37f2b53a
BLAKE2b-256 checksum
How to use checksums
dc0d54c792598904da0e5c176992f2595e4fab7ed40c22c643d1874514b52bf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ctorrepr 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page