represent.core#
Note
Names in this module should be imported from represent. They are in represent.core for structural reasons.
- class represent.core.ReprHelperMixin[source]#
Bases:
objectMixin to provide
__repr__and_repr_pretty_forIPython.lib.prettyfrom user defined_repr_helper_function.For full API, see
represent.helper.BaseReprHelper.def _repr_helper_(self, r): r.positional_from_attr('attrname') r.positional_with_value(value) r.keyword_from_attr('attrname') r.keyword_from_attr('keyword', 'attrname') r.keyword_with_value('keyword', value)
New in version 1.3.
- represent.core.autorepr(*args, **kwargs)[source]#
Class decorator to construct
__repr__automatically based on the arguments to__init__._repr_pretty_forIPython.lib.prettyis constructed unless include_pretty=False.__rich_repr__forrich.prettyis constructed unless include_rich=False.- Parameters:
positional – Mark arguments as positional by number, or a list of argument names.
include_pretty – Add a
_repr_pretty_to the class (defaults to True).include_rich – Add a
__rich_repr__to the class (defaults to True).
Example:
>>> @autorepr ... class A: ... def __init__(self, a, b): ... self.a = a ... self.b = b >>> print(A(1, 2)) A(a=1, b=2)
>>> @autorepr(positional=1) ... class B: ... def __init__(self, a, b): ... self.a = a ... self.b = b >>> print(A(1, 2)) A(1, b=2)
New in version 1.5.0.