represent.helper#
Note
Names in this module should be imported from represent. They are in represent.helper for structural reasons.
- class represent.helper.BaseReprHelper(other)[source]#
- abstract positional_from_attr(attr_name)[source]#
Add positional argument by retrieving attribute attr_name
- Parameters:
attr_name (str) – Attribute name such that
getattr(self, attr_name)
returns the correct value.
- abstract positional_with_value(value, raw=False)[source]#
Add positional argument with value value
- Parameters:
value – Value for positional argument.
raw (bool) – If false (default),
repr(value)
is used. Otherwise, the value is used as is.
- class represent.helper.ReprHelper(other)[source]#
Bases:
BaseReprHelper
Help manual construction of
__repr__
.It should be used as follows:
def __repr__(self) r = ReprHelper(self) r.keyword_from_attr('name') return str(r)
Changed in version 1.4: parantheses property added. Must be set before str(r) is called:
def __repr__(self) r = ReprHelper(self) r.parantheses = ('<', '>') r.keyword_from_attr('name') return str(r)
- positional_from_attr(attr_name)[source]#
Add positional argument by retrieving attribute attr_name
- Parameters:
attr_name (str) – Attribute name such that
getattr(self, attr_name)
returns the correct value.
- positional_with_value(value, raw=False)[source]#
Add positional argument with value value
- Parameters:
value – Value for positional argument.
raw (bool) – If false (default),
repr(value)
is used. Otherwise, the value is used as is.
- class represent.helper.PrettyReprHelper(other, p, cycle)[source]#
Bases:
BaseReprHelper
Help manual construction of
_repr_pretty_
forIPython.lib.pretty
.It should be used as follows:
def _repr_pretty_(self, p, cycle) with PrettyReprHelper(self, p, cycle) as r: r.keyword_from_attr('name')
Changed in version 1.4: parantheses property added. Must be set before
PrettyReprHelper.open()
is called (usually by context manager).def _repr_pretty_(self, p, cycle) r = PrettyReprHelper(self, p, cycle) r.parantheses = ('<', '>') with r: r.keyword_from_attr('name')
- positional_from_attr(attr_name)[source]#
Add positional argument by retrieving attribute attr_name
- Parameters:
attr_name (str) – Attribute name such that
getattr(self, attr_name)
returns the correct value.
- positional_with_value(value, raw=False)[source]#
Add positional argument with value value
- Parameters:
value – Value for positional argument.
raw (bool) – If false (default),
repr(value)
is used. Otherwise, the value is used as is.
- keyword_from_attr(name, attr_name=None)[source]#
Add keyword argument from attribute attr_name
- Parameters:
Changed in version 1.4: Method argument names swapped, didn’t make sense before.
- class represent.helper.RichReprHelper(other)[source]#
Bases:
BaseReprHelper
Help manual construction of
__rich_repr__
forrich.pretty
.It should be used as follows:
def __rich_repr__(self) r = RichReprHelper(self) r.keyword_from_attr('name') yield from r
- positional_from_attr(attr_name)[source]#
Add positional argument by retrieving attribute attr_name
- Parameters:
attr_name (str) – Attribute name such that
getattr(self, attr_name)
returns the correct value.
- positional_with_value(value, raw=False)[source]#
Add positional argument with value value
- Parameters:
value – Value for positional argument.
raw (bool) – If false (default),
repr(value)
is used. Otherwise, the value is used as is.