Skip to content

Alignment Rules

The alignment rules pad the space before a shared token across consecutive rows so the token sits at one column, and the assignments, annotations, patterns, and trailing comments in a run then read as vertical groups. The column math lives in the Aligner primitive, and each rule supplies the walker that reads which rows form a group. The per-rule max-shift facet limits how much padding one row may take, where each rule reads a run in source order and starts a new group at the first row whose gap from the narrowest row would exceed the limit. Setting it to false removes the limit, so a run of any width aligns on one column, and 0 forbids padding altogether. A # prose: skip keeps a row out of its group, so the rules read past a skipped single-line row and align the rows around it together, whereas a skipped multi-line statement ends the run.

align-colons

Alignment

Pads the space before : so consecutive dict entries, annotated assignments, signature annotations, and docstring entries share one column, with a docstring entry's parenthesized type in a column of its own.

align-comments

Alignment

Pads the gap before each trailing comment in a run so every # sits at one shared column.

align-comparisons

Alignment

Pads the space before each comparison operator in a multi-line and or or chain so the operators share one column.

align-equals

Alignment

Pads the space before = so consecutive assignments, annotated parameter defaults, and an exploded call's keyword arguments share one column.

align-imports

Alignment

Pads the space before the import keyword across consecutive from imports, or before as across consecutive aliased imports, so the keywords share one column.

align-match-case

Alignment

Folds each single-statement case arm onto one line and pads the space before its : so consecutive arms share one column.

strip-stranded-padding

Alignment

Removes padding that lines up with nothing, before the : of a one-member group and just inside a bracket, and settles the gap after a : to one space.

The Configuration reference lists the per-rule facets, and the Aligner primitive covers the math the rules share. The ColonTargets walker finds the : contexts the alignment rules read.