Mixin class for concise object representation
Project description
Python mixin class for concise object representation
This library offers a mixin class ReprMixin
that implements the __repr__
and _repr_pretty_
methods to represent objects in a concise way.
The implementation is based on the class __init__
method signature,
and will consider whether its parameters are positional or optional
to construct a representation as succinct as possible.
Positional arguments are represented as values only and
optional arguments are included only when different from their default value.
Please note this is intended to be used on lightweight classes that map arguments to attributes.
Also it will not work with dataclasses that override the __repr__
method.
Usage
from lazyrepr import ReprMixin
class MACD(ReprMixin):
def __init__(self, short=12, long=26, signal=9, *, percent=False):
self.short = short
self.long = long
self.signal = signal
self.percent = percent
obj = MACD()
print(obj) # >>> MACD(12, 26, 9)
Examples
Examples notebooks are in the extras
folder.
Installation
You can install this package with pip
.
pip install git+ssh://git@github.com/furechan/lazyrepr.git
Related Projects
- easyrepr Python decorator to automatically generate repr strings
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 Distributions
Built Distribution
File details
Details for the file lazyrepr-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: lazyrepr-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b623d0c31b96752273a0f03bcfaf7dd9126ea7008f814857f2c165d10101df10 |
|
MD5 | efbfd1df4b43ae988db3e86c93b3a058 |
|
BLAKE2b-256 | 9ad64981ca9840de0e6d5824f5a6b46f651a131ba2f976c03511e0b5db958b3a |