prpc.utils.ReprBuilder

class prpc.utils.repr_builder.ReprBuilder(obj)

Simple utility to build string reprs for objects.

Motivation: __repr__ output is used directly in debug logs, so avoiding writing some lengthy string arguments may be important.

Allows nice chain syntax, e.g.:

(utils.ReprBuilder(self)
  .add_value("method", self.method)
  .add_value("call_type", self.CALL_TYPE)
  .add_iterable("args", self.args)
  .add_mapping("kwargs", self.kwargs)
  .format(module_name=False))
Parameters:obj – Object to build repr to.
add_value(name, value, max_len=36)

Add key-value pair to object description

add_iterable(name, value, max_element_len=16, max_total_len=256)

Add key-iterable pair to object description.

add_mapping(name, value, max_key_len=16, max_element_len=16, max_total_len=512)

Add key-mapping pair to object description.

format(id=False, module_name=False)

Format the final result.

Parameters:
  • id (bool) – Toggle adding object id to the repr.
  • module_name (bool) – Toggle appending full module name to the type name.
Returns:

Formatted repr string.