Wadler-Lindig is a Python library that provides a pretty-printer based on the Wadler–Lindig algorithm. It serves as an alternative to the built-in `pprint.pprint`, aiming to produce output that consumes less horizontal space, which is particularly useful for complex custom types, error messages, or nested data structures. The library is characterized by its compact implementation, support for multi-line strings and ANSI escape codes, and zero runtime dependencies. The current version is 0.1.7, and it appears to be actively maintained.
pip install wadler-lindigVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic usage of `wadler_lindig.pprint` and `pformat` with a dataclass containing a list and a NumPy array. It also illustrates how to customize the pretty-printing for a custom class using the `__pdoc__` method. Note that `numpy` is used for demonstration purposes, but is not a core dependency of the `wadler-lindig` library itself.
Design custom `__pdoc__` methods or preprocess long strings if strict width adherence is critical for specific parts of the output.
For your types, implement `def __pdoc__(self, **kwargs) -> wl.AbstractDoc: ...`. For external types, pass `custom=your_custom_function` to the pretty-printing calls.
Understand its purpose as an object introspection and display tool. For source code formatting, use dedicated tools like Black or Ruff.
If expecting exact `pprint` behavior, be aware of these differences. For NumPy array verbosity, set `short_arrays=False` in `pprint`/`pformat` calls. Adapt custom pretty-printing logic if migrating from `pprint`.