coexist.utilities.autorepr#
- coexist.utilities.autorepr(_c=None, *, short={}, hide={})[source]#
Automatically create a
__repr__
method for pretty-printing class attributes; they are discovered at runtime following some rules.Attribute names do not start with underscores and are not callable.
The attributes given in
short
(set[str] | bool) are printed up to 80 characters. Ifshort == True
, then all attributes are shortened.The attributes given in
hide
(set[str]) are skipped.If the attribute representation is multiline (i.e. has newlines) then it is printed on a separate line and indented with 2 spaces.
Examples
>>> @autorepr >>> class SomeClass: >>> def __init__(self): >>> self.x = "spam" >>> self.y = "eggs" >>> >>> print(SomeClass()) SomeClass --------- x = spam y = eggs
>>> @autorepr(hide = {"x"}) >>> class SomeClass: >>> def __init__(self): >>> self.x = "spam" >>> self.y = "eggs" >>> >>> print(SomeClass()) SomeClass --------- y = eggs