Mixin class for concise object representation
Project description
Python utilities for concise object representation
This library provides utilities to implement the __repr__
and ipython _repr_pretty_ methods to represent objects in a concise manner.
The implementation is based on the class __init__ method signature,
and will differentiate between positional and optional parameters
in order to make the representation as succinct as possible.
These methods are intended to be used on simple classes that map all their constructor arguments to attributes. Also note that dataclasses already implement a similar __repr__ method by default.
Usage
To add a basic representation to a class you can overrides its __repr__ method with lazy_repr as follows:
from lazyrepr import lazy_repr
class MyClass:
__repr__ = lazy_repr
...
To provide both __repr__ and ipython _repr_pretty_ for a class just inherit from ReprMixin
from lazyrepr import ReprMixin
class MyList(ReprMixin):
def __init__(self, item=()):
self.items = list(items)
lst = MyList(range(3))
print(lst) # >>> MyList([0, 1, 2])
Examples
Examples notebooks are in the extras folder.
Installation
You can install this package with pip.
pip install lazyrepr
Related Projects and Resources
- easyrepr Python decorator to automatically generate repr strings
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazyrepr-0.0.4-py3-none-any.whl.
File metadata
- Download URL: lazyrepr-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b18e44fa59274ef57e3b03b3dd38cb35e77bfcecd1cf8b21360623343a108b20
|
|
| MD5 |
6c03c410a1b7086b894f6b1cebab3dbf
|
|
| BLAKE2b-256 |
9860bc7cdbb4e47579a4c57b009bb141593d85b11081920472f023b0092a537b
|