Skip to main content

A mixin class for concise object representation

Project description

Python mixin class for automatic 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

lazyrepr-0.0.1-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page