Skip to content

signature-layout

A function signature reads as either a one-line declaration or a stacked column of parameters. Mixed shapes (part on the def line, the rest indented underneath) force the reader to track two layout idioms at once.

collapses every signature to the binary canonical form, deciding the shape from code-line-length and max-inline-params.

The rule expands a signature when its inline form overflows the configured code-line-length, or when its parameter count exceeds max-inline-params. Otherwise the signature collapses to a single line. A comment inside the parameter list pins the existing shape, because moving the parameters would orphan the comment from its anchor. The expanded form lays each parameter on its own line, indented one step past the def, with the closing ) flush left and the return annotation trailing on the same line.

Configuration

KeyTypeDefaultMeaning
enabledbooltrueToggle the rule on or off
max-inline-paramspositive int | false4Cap on the parameter count an inline signature can carry. Setting false disables the count trigger and leaves only the line-length budget

The line-length budget comes from the top-level code-line-length key (default 88), which the rule reads directly. Setting max-inline-params to false makes the rule expand purely on line length, leaving inline-but-long signatures untouched when they fit the budget regardless of parameter count.

The Canonical Case

A five-parameter signature whose inline form fits the line budget pins the count trigger firing alone. The rule expands solely on the parameter count exceeding max-inline-params.

python
def render(
    width: int,
    height: int,
    depth: int,
    scale: int,
    fast: bool,
):
    return (width, height, depth, scale, fast)

More Examples

A signature whose parameters overflow the line budget expands to one per line, while the parenthesized multi-line return annotation passes through with its grouping parentheses intact. Those parentheses are what let the return type span several lines, so dropping them would leave output that no longer parses.

A three-parameter signature whose inline form overflows the default code-line-length of 88 columns expands, with the parameter count comfortably under the cap. The length trigger fires alone.

A two-parameter signature already in expanded shape, whose inline form fits under both thresholds, collapses back to a single line. The reverse direction of the rewrite is symmetric with expansion.

An outer async def and an inner sync def each trip the count trigger and expand at their own indents. The walker descends recursively rather than stopping at the outer body.

A class method with self and four typed parameters trips the count trigger and expands at the class-body indent. The walker descends into class bodies the same way it descends into top-level defs, deriving the indent from the method's own def position.

A @cache-decorated function with five parameters trips the count trigger and expands. The decorator surface stays untouched, because the replacement range starts at (, leaving everything above the def keyword out of scope.

A single typed parameter in expanded shape collapses to an inline signature once the inline form fits under both thresholds. The return annotation trails the closing ) on the same line, rather than landing on its own line.

No Change

Two signatures already at their canonical shape pass through unchanged. The inline two-parameter form fits both thresholds, and the expanded five-parameter form trips the count trigger yet already lands at the rewrite target, so the rule makes no edit on either.

No Change

A comment anywhere between ( and ) pins the existing shape, overriding both count and length triggers. Each pinned signature keeps its comment in place rather than getting rewritten around, covering both own-line and trailing-line placements.

No Change

The parameters fit on one line, so they are left inline even though the return annotation spans several lines. The line-budget check measures the header up to the return annotation rather than the annotation's own wrapped width, so a tall return type no longer drags fitting parameters onto separate lines.