align-colons
AlignmentProse aligns the : separator across dict literals, Args: blocks.
A multi-line boolean chain (and or or) of comparison operands reads as a small table where the operator anchors the relationship between left and right. When each operator sits at a different column the eye walks across each line individually, treating the chain as five sentences rather than one parallel structure.
The rule walks each BoolOp whose operands are all Expr::Compare. The widest operand's left side fixes the shared column, with variable-width operators (==, <=, is not) right-aligning so the operator's last character sits in the shared column. A chained compare (0 < x < 100) anchors on its first operator only. A non-comparison operand, a multi-line operand, or a blank line in the gap breaks the run.
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Toggle the rule on or off |
max-shift | positive int | 8 | Ceiling on per-line padding |
max-shift-policy | "split" | "drop" | "split" | How to handle a max-shift. See the per-rule knobs for the full semantics |
max-shift caps the per-line padding the alignment can introduce, and max-shift-policy resolves the fallback when a group's widest operand would push the operator column past the cap. The per-rule knobs reference covers the "split" / "drop" semantics.
Three single-comparator == operands in a multi-line and-chain share an alignment column. The operator at each row sits one space past the widest operand's left side.
if (
foo == 1
and bar_baz == 2
and quux == 3
):
pass
A
A chained compare such as 0 < bar < 100 anchors on its first operator. The remaining operators stay in place and take no part in the column math, while the surrounding single-comparator rows align around it.
An operand whose own range spans multiple source lines breaks the run. The parenthesized (1 + 2) operand pushes its neighbors out of column, leaving the trailing rows to align among themselves.
A comment on its own line between two operands pushes them onto non-adjacent source lines, so the line-distance check breaks the run regardless of comment content. The rows below the divider still align among themselves.
A call expression on the left side qualifies for the len(b), counts as the left-hand side that the operator column pads against.
Identity and membership operators join the same aligned == and <. The wider is not and not in widen the operator column, and every other operator's last character lands at the shared right edge.
== operands and < operands share one aligned = of == and the < land in the same column.
Operands across an or chain align with the same column math the rule applies to and chains. The == of each row settles one space past the widest operand's left side.
An and-chain whose == already sit one space past the widest left side is
Prose aligns the : separator across dict literals, Args: blocks.
Prose aligns the = separator across consecutive single-target assignments and annotated function-parameter defaults.
Prose aligns the import and as keywords across consecutive import statements.
Prose alphabetizes import siblings, dict-key blocks, and
Prose aligns the post-pattern : across single-expression case bodies inside a match statement.