Skip to content

repr_util⚓︎

YAML-based repr mixin for structured objects.

Compared to bare yaml.dump(), this module adds:

  • numpy support: 1-D arrays serialise as inline lists; N-D arrays use block literal style (|) so they render like str(arr) without truncating to a single line.
  • numpy scalar support: np.int64 etc. are unwrapped to Python scalars instead of emitting a !!python/object/apply tag.
  • YamlRepr mixin: gives any class a __repr__ driven by _repr_fields() — override that method to control which fields appear and under what names.
  • nested YamlRepr objects: registered via add_multi_representer so they inline naturally when nested inside another.
  • unknown-type fallback: anything without a representer falls back to repr(obj) as a plain string, rather than raising RepresenterError.

YamlRepr ⚓︎

Mixin: YAML-formatted repr driven by _repr_fields().

yaml_repr(obj) ⚓︎

Return a compact YAML string for any object.