hbutils.model.repr

Overview:

Useful functions for build representation format of object.

get_repr_info

hbutils.model.repr.get_repr_info(cls: type, args: List[Tuple]) → str[source]
Overview:

Get representation information for object. Can be used in __repr__ method for class.

Arguments:
  • cls (type): Object’s type.

  • args (List[Tuple]): Argument display information.

Returns:
  • repr (str): Representation string.

Examples::
>>> from hbutils.model import get_repr_info
>>> class Sum:
...     def __init__(self, a, b):
...         self.__a = a
...         self.__b = b
...     def __repr__(self):
...         return get_repr_info(
...             cls=self.__class__,
...             args=[
...                 ('b', lambda: self.__b, lambda: self.__b is not None),
...                 ('a', lambda: self.__a),
...             ]
...         )
...
>>> Sum(1, 2)
<Sum b: 2, a: 1>
>>> Sum(1, None)
<Sum a: 1>
>>> Sum(None, None)
<Sum a: None>