align-colons
AlignmentProse aligns the : separator across dict literals, Args: blocks.
An alignment group exists to give the reader's eye a column to drop down. With two or more members the column carries information, where each row reads as a row in a table. With exactly one member the column becomes a single cell, and padding it to a width that no sibling matches adds visual noise without payoff.
strips the pre-: padding from every :-alignment context that resolves to a single member, so a one-key dict, a one-arg signature, or a one-field dataclass reads as plain code instead of a one-row table.The rule operates on the :-shaped contexts that
Args: blocks) plus the single-expression match-arm context that covers. Multi-member groups whose :s sit on distinct lines pass through this rule untouched, since the colon-alignment surfaces own them. The =-alignment from and the import-keyword alignment from carry their own one-member fallbacks and don't need pruning here.| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Toggle the rule on or off |
enabled. Turning it off leaves one-member alignment contexts as one-row tables (a one-key dict reading with the same padding a multi-key dict would carry), which is rarely what a project wants in practice.A one-key dict literal drops its pre-: padding, reading as a plain key-value pair rather than a one-row table.
single = {"only_key": compute_value()}
paired = {
"first" : 1,
"second" : 2,
}
nested = {
"outer": {"inner": "value"},
}
A Args: section with one entry strips the pre-: padding on that entry. A section with two or more entries keeps its padding for align_colons to align in a separate pass.
A single-parameter signature with extra padding before its : is the canonical singleton shape, so the rule strips that padding to zero. Multi-parameter signatures collapsed onto one line do the same, because every : shares a line and has no column to align against. Spread across multiple lines, they stay padded for align_colons.
A pre-collapsed one-arm match carries one space before its colon. The rule strips the gap, leaving the : flush against the pattern.
A multi-line single-parameter signature strips its pre-: padding, since the lone parameter and its : share a line with non-zero width. A multi-line multi-parameter signature qualifies two distinct-line members, so the rule defers to align_colons and the padding stays.
Class fields, dict literals, and function parameters interleave singleton contexts with multi-item groups. Singletons strip their pre-: padding while multi-line multi-item groups stay padded for align_colons. A multi-item : have no column to align against.
An unannotated self yields a None that splits the parameter slice into runs. A method with one annotated parameter after self forms a singleton run that strips its pre-: padding, as does a keyword-only parameter introduced by *. Two annotated parameters land a size-two run on one line, which strips because same-line : have no column to align against.
Every singleton context already carries zero pre-: padding. The rule recognizes each gap as empty and emits no edits, so the output equals the input byte-for-byte and the
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 aligns the post-pattern : across single-expression case bodies inside a match statement.