epy.pretty_repr_top_level

epy.pretty_repr_top_level#

etils.epy.pretty_repr_top_level(
obj: Any,
*,
force: bool = True,
) str[source]

Pretty repr(obj) for nested list, dict, dataclasses,…

This version do not use @reprlib.recursive_repr() to avoid bug when used inside __repr__:

@dataclasses.dataclass  # Or @attrs.frozen,...
class A:

  def __repr__(self):
    return epy.pretty_repr_top_level(self)

print(repr(A()))
Parameters:
  • obj – Object to display

  • force – Force the pretty_repr, even if the object has a custom __repr__. This is useful when the __repr__ implementation itself want to call pretty_repr(self).

Returns:

Repr