align-colons
AlignmentPads 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-comparisons pads the space before each comparison operator in a multi-line and or or chain so the operators share one column, and the chain then reads top to bottom as one parallel structure, each left operand beside its right, rather than as a stack of separate sentences the eye reads one at a time.
The rule reads each BoolOp whose operands are all Expr::Compare. The widest left operand sets the shared column, and operators of differing widths (==, <=, is not) right-align so the last character of each sits in that column. A chained compare (0 < x < 100) aligns on its first operator only. A non-comparison operand, a multi-line operand, or a blank line between operands ends the run.
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Turns the rule on or off. |
max-shift | positive int | 0 | false | 16 | How far apart the widest and narrowest rows of a run may be for the run to still align on one column. A positive N caps that gap, 0 forbids any padding so every row sits flush, and false lifts the cap so a run of any width aligns on one column. A row marked # prose: skip stays out of its group. |
max-shift limits how much padding one operator may take. The rule reads each run of comparisons in source order and extends a column while the gap between the widest and narrowest left operands stays within the limit, starting a new column at the first row that would exceed it. Setting max-shift to false removes the limit, so a run of any width aligns on one column, and 0 forbids padding altogether. The per-rule facets reference covers the full semantics.
The multi-line and chain compares foo, bar_baz, and quux with one == apiece. Every == moves to one space past the widest left operand, the and bar_baz row, so the three comparisons read as one parallel list.
if (
foo == 1
and bar_baz == 2
and quux == 3
):
pass
A blank line separates foo == 1 from the bar_baz and qux rows below it. The blank line ends the run, so foo keeps its == where it was written and bar_baz and qux align on a column of their own.
The left operands are foo, the call len(b), and qux. A call expression joins the group like any other left operand, so len(b), the widest, sets the column and the == after foo and qux pad out to it.
The chained compare 0 < bar < 100 sits between the foo == 1 and qux == 3 rows. Only its first < moves to the shared column, and the second < stays where it was written and takes no part in the column math.
foo compares against a parenthesized 1 + 2 that spans several lines, above bar_baz == 3 and qux == 4. The multi-line operand ends the run, so the foo row takes no padding and bar_baz and qux align with each other below it.
The or chain compares foo, bar_baz, and quux with one == apiece. The or chain aligns exactly as an and chain does, so each == moves to one space past the widest left operand, the or bar_baz row.
The comment # divider takes a line of its own between foo == 1 and bar_baz == 2. The comment line ends the run, whatever its text says, because the two rows are no longer on adjacent source lines, so foo keeps its == as written and bar_baz and qux align below the comment.
The chain mixes == and < with the identity operators is and is not and the membership operators in and not in. All of them join one alignment group, and the wider is not and not in widen the column, so the last character of every operator sits at the shared right edge.
The == rows for foo and bar_baz and the < rows for qux and quux form one alignment group. The operators right-align, so the second = of each == and each one-character < sit in the same column.
The and chain over foo, bar, and qux already has each == one space past the widest left operand. The rule emits no edit, so the source passes through unchanged.
evaluate opens with three record.get assignments and then guards on a multi-line BoolOp. align-equals pads the assignment run's = into one column, and align-comparisons right-aligns the is, ==, and < operators in a column of their own inside the if, the two columns independent of each other.
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.
Pads the space before = so consecutive assignments, annotated parameter defaults, and an exploded call's keyword arguments share one column.
Pads the space before the import keyword across consecutive from imports, or before as across consecutive aliased imports, so the keywords share one column.
Sorts sibling entries whose order carries no meaning, covering import names, dict keys, class-body members, keyword arguments, and docstring entries.
Folds each single-statement case arm onto one line and pads the space before its : so consecutive arms share one column.
Rewrites a comparison to state its check directly, using is against None, putting the variable side first, and folding a leading not into its operator.