Skip to content

shed-parentheses

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.

Configuration

KeyTypeDefaultMeaning
enabledbooltrueToggle the rule on or off

The Canonical Case

A parenthesis pair that wraps an expression without binding anything sheds, so total = (base + tax) reflows to total = base + tax.

python
total = base + tax
label = name

More Examples

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 annotation sheds, so def total() -> (int): reflows to def total() -> int:.

No Change

A generator expression is illegal without its surrounding parentheses, so the pair stays.

No Change

The parentheses that form a tuple belong to the tuple rather than wrapping it, so a one-element tuple keeps them.

No Change

A grouping whose interior carries a comment keeps its parentheses, since folding the break would strand the comment off the line it describes.

No Change

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.

No Change

An assignment expression keeps its pair whatever the surrounding context, leaving the binding readable as one rule rather than a positional exception.

No Change

A wrapped grouping whose folded form would overflow the budget keeps its parentheses across the lines it spans.

For per-line opt-outs, the Suppression chapter covers the # prose: skip[shed-parentheses] directive.