Skip to main content

wadler-lindig-parts

A parts layer over wadler-lindig: one engine behind repr, str, __format__ and the representations Jupyter asks for.

A type joins in by saying what it is made of, not how it renders. Register pparts and the type gets every markup, every value form and the value format spec — including axes added later by somebody else.

>>> import dataclasses
>>> from wadler_lindig_parts import PPart, pparts, pspec

>>> @dataclasses.dataclass
... class Version:
...     major: int
...     minor: int
...
...     def __repr__(self) -> str:
...         return pspec(self, "bare")
...
...     def __format__(self, spec: str, /) -> str:
...         return pspec(self, spec)

>>> @pparts.dispatch
... def _(obj: Version, /, *, markup="text", **kw):
...     return (
...         PPart("major", str(obj.major)),
...         PPart("dot", ".", "sep"),
...         PPart("minor", str(obj.minor)),
...     )

>>> v = Version(2, 1)
>>> v
2.1
>>> f"{v:html}"
'<span>2</span>.<span>1</span>'
>>> f"{v:latex}"
'$2.1$'

One pparts method, two lines of plumbing, and four output routes that cannot disagree.

ReprMixin writes those two methods for you and adds __str__, the Jupyter hooks and a __pdoc__. Most types do not need a base class for two short methods, so the examples here write them out; see how to make a type formattable for both routes side by side.

Install

pip install wadler-lindig-parts

Two runtime dependencies, wadler-lindig and plum-dispatch, and nothing else — ever. A test parses every module and fails on any import outside that set plus the standard library, so a third dependency cannot be added without someone deliberately deleting that test.

Register axes before defining classes that name them

This one is about ReprMixin, which resolves __repr_spec__ when the class is created, not at first print. So a spec naming an axis or alias that is not yet registered fails at the class statement:

>>> from wadler_lindig_parts import Axis, ReprMixin, register_axis, unregister_axis

>>> try:
...     class TooEarly(ReprMixin):
...         __repr_spec__ = "call-vecform"
... except ValueError as e:
...     print("class creation failed:", str(e).split(":")[0])
class creation failed: invalid format spec 'call-vecform'

>>> _ = register_axis(Axis(
...     name="vector_form",
...     keywords={"vecform": True},
...     default=False,
...     layouts={"call": lambda v: {"vector_form": v}},
... ))
>>> class NowFine(ReprMixin):
...     __repr_spec__ = "call-vecform"
>>> NowFine._repr_spec_parsed["vector_form"]
True
>>> unregister_axis("vector_form")

Inside one package that was a statement about the order of lines in an __init__.py. Between two installed distributions it is load order between them: register your axes at import of your own package, before importing or defining the classes whose repr specs use them. The error arrives at a class statement that looks unrelated to the registration, which is why it is written down here rather than left to the message.

A spec written inside __repr__ is parsed on each call instead, so the plain route has no ordering requirement: the same mistake surfaces at the first print, naming the spec.

Keywords share one flat namespace

Every registering distribution writes into the same keyword index, so a run of keywords can be written in any order — html-bare and bare-html are the same request. Two packages may want the same word, and both registrations succeed: the bare word then raises and names both claimants, while axis=word keeps working for each.

A collision therefore costs one word in one spec, not a rewrite and not a registration. A package expecting to share vocabulary can write the qualified form from the start.

Documentation

https://galacticdynamics.github.io/wadler-lindig-parts

New to the package? Make your first formattable type builds one from nothing in a few minutes. Already building something? The how-to guides are task-sized, and the reference has the spec grammar and every public name.

Metadata

Release files for wadler-lindig-parts 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wadler-lindig-parts 0.3.0
File Size Uploaded Provenance Actions
wadler_lindig_parts-0.3.0.tar.gz 69.8 kB With provenance Details for wadler_lindig_parts-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wadler-lindig-parts 0.3.0
File Interpreter ABI Platform Actions
wadler_lindig_parts-0.3.0-py3-none-any.whl Python 3 none any Details for wadler_lindig_parts-0.3.0-py3-none-any.whl

Total release size: 98.1 kB

Release files / wadler_lindig_parts-0.3.0.tar.gz

Download URL wadler_lindig_parts-0.3.0.tar.gz
Size 69.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bedf88b7a7634ae76cf0d513da9edef5514582b948d55a4634021ec33e25d1e0
BLAKE2b-256 checksum
How to use checksums
4a2191105479d3706aecb5fc86a4ab7b7995035f260a170cd416787f76090fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / wadler_lindig_parts-0.3.0-py3-none-any.whl

Download URL wadler_lindig_parts-0.3.0-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63cac524c3ee7545b1b76f2a15da2c89f09122c8e3efdfe7cdc6c8942e59baa1
BLAKE2b-256 checksum
How to use checksums
91deb2a3a69768375e52cc9ed50b2df7534f542c7e4e5858e9fbef29f9c19974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for wadler-lindig-parts 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for wadler_lindig_parts-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page