MappingReprMixin#
- class brainstate.util.MappingReprMixin[source]#
Mapping mixin for pretty representation.
This mixin only supplies a
__pretty_repr__implementation (the hook consumed bypretty_repr_object()); it does not override__repr__or__str__. In particular, mixing it intodictdoes not change how the object prints, becausedict.__repr__still wins via the MRO. To obtain the multi-line pretty string you must route throughpretty_repr_object(), which also requires the object to be aPrettyReprinstance.Examples
>>> from brainstate.util._pretty_repr import ( ... MappingReprMixin, PrettyRepr, pretty_repr_object ... ) >>> >>> # Combine with ``PrettyRepr`` and expose the pretty output through an >>> # explicit ``__repr__`` (``dict.__repr__`` would otherwise shadow it). >>> class PrettyDict(dict, MappingReprMixin, PrettyRepr): ... def __repr__(self): ... return pretty_repr_object(self) ... >>> print(PrettyDict({'a': 1, 'b': 2})) { 'a': 1, 'b': 2 }