collection-layout
FormattingSplits list, tuple, dict, and set literals into one-entry-per-line layout once they overflow their width, or a dict crosses an entry-count cap.
A parenthesis pair wrapped around an expression only to span lines, or out of habit, is visual weight the expression does not carry meaning through.
joins a wrapped construct back onto the line it fits, yet it leaves the surrounding parentheses in place, because removing syntax belongs to no layout rule. closes that gap, dropping a grouping pair that binds nothing and reflowing the expression onto the line it now fits.The decision is structural rather than textual, so a pair sheds only where removing it leaves the parse unchanged. A precedence-bearing pair such as (a + b) * c stays because dropping it would rebind the multiplication, a generator and a walrus binding keep the parentheses the grammar requires of them, and the parentheses that form a one-element tuple stay part of the tuple rather than wrapping it. A pair whose interior carries a comment stays too, since folding the break would strand the comment off the line it describes.
A wrapped multi-line grouping folds onto one line when the bare form fits the budget and stays wrapped when it would overflow, so a short boolean condition reads as one clean line whereas a long one keeps its parentheses across the lines it needs. A pair nested inside another redundant pair sheds in the same pass.
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Toggle the rule on or off |
A parenthesis pair that wraps an expression without total = (base + tax) reflows to total = base + tax.
total = base + tax
label = name
A wrapped grouping whose single-line form fits the budget sheds and folds onto one line, so the condition reflows to ready = server.up and cache.warm.
A redundant pair around a single-line return def total() -> (int): reflows to def total() -> int:.
A generator expression is illegal without its surrounding parentheses, so the pair stays.
The parentheses that form a tuple belong to the tuple rather than wrapping it, so a one-element tuple keeps them.
A grouping whose interior carries a comment keeps its parentheses, since folding the break would strand the comment off the line it describes.
A pair that binds tighter than the operator enclosing it stays, since dropping it would rebind the expression. Both (base + bonus) * factor and 2 ** (depth + 1) keep their parentheses.
An assignment expression keeps its pair whatever the surrounding context, leaving the
A wrapped grouping whose folded form would overflow the budget keeps its parentheses across the lines it spans.
Splits list, tuple, dict, and set literals into one-entry-per-line layout once they overflow their width, or a dict crosses an entry-count cap.
Normalizes function signatures to one line or one parameter per line, gated by line length and inline-parameter count.
For per-line opt-outs, the Suppression chapter covers the # prose: skip[shed-parentheses] directive.