Skip to content

align-colons โ€‹

The : separator appears across the contexts below, wherein columns of values sit beside columns of names and the reader's eye wants a tidy table rather than a ragged margin.

gathers those contexts into a single shared alignment surface, so dictionary keys, dataclass and Pydantic fields, function-signature parameter annotations, and docstring Args: blocks all read as parallel two-column entries. Single-expression match arms live in a separate dispatch table owned by .

The rule walks each context independently, treating a group as the consecutive members sharing the same indentation level and parent shape. A blank line, an own-line comment, or a non-member statement resets the group. Alignment honors the

so that one-member contexts skip padding altogether, leaving a one-key dict reading as plain code instead of a one-row table.

Configuration โ€‹

KeyTypeDefaultMeaning
enabledbooltrueToggle the rule on or off
max-shiftpositive int8Ceiling on per-line padding
max-shift-policy"split" | "drop""split"How to handle a group whose widest member exceeds max-shift. See the per-rule knobs for the full semantics

max-shift caps the per-line padding the alignment can introduce. When a group's widest member would push the column past the cap, max-shift-policy decides the fallback shape ("split" partitions the group, "drop" excludes the widest members from the padding calculation). The per-rule knobs reference covers the full semantics.

The Canonical Case โ€‹

A dictionary literal whose entries have differing key lengths aligns on the : separator, and the reader reads keys and values as separate columns.

python
capitals = {
    "USA"    : "Washington",
    "France" : "Paris",
    "Japan"  : "Tokyo",
    "Spain"  : "Madrid",
}

More Examples โ€‹

An own-line comment between two entries closes the run and starts a fresh one, so the entries above and below the comment align on their own columns rather than one shared column. A trailing comment rides with its entry, whereas a standalone comment line breaks the run.

A run mixing commented and bare entries aligns to a single : column across the whole dict rather than splitting at the commented rows, because each comment attaches to its entry rather than to the alignment.

A dict whose entries each carry a trailing comment aligns its : separators on the shared column, with each comment left riding after its value. The comment is an annotation on the entry, so it never blocks the alignment.

The phrase Args: appears both in the docstring's body prose and as the real section header. Only the header triggers alignment, leaving the inline mention as-is while the named entries beneath the header align on one : column.

Every annotated parameter on a multi-line signature settles its : onto a shared column at the widest name's width. The return-type : closing the signature line sits outside the parameter group and stays untouched.

A dict mixes string literals, an integer literal, and a bare name reference as keys. The math runs on each key's display width, so the : lines up identically regardless of the key expression's kind.

A dict whose values are themselves dicts has each nested dict aligning its own : column at its own indent. The inner alignment is unaffected by the outer dict's key widths.

A dict mixes key: value entries with a **defaults unpacking. The unpacking carries no key expression, so it drops out of the alignment group while the keyed entries around it align on a shared : column.