Skip to content

unsorted-parameters

Alphabetical parameters give a reader the same landmarks in a signature that

gives them everywhere else. Prose will not reorder them for you, though, because a parameter's position is part of the function's contract. Every positional call binds by slot, and a single-file formatter cannot see the callers in other modules, in frameworks, or behind dynamic dispatch, so moving a parameter would silently rebind them. reports the out-of-order run instead, leaving the reorder to a hand that can weigh the callers.

The lint fires only where acting on it could be reasonable, a module-level or nested free function whose positional-or-keyword parameters are out of alphabetical order, required parameters before optional. It stays silent everywhere a reorder would be unsafe to even suggest. A class-body method draws nothing, since its callers routinely live outside the module. A function under a positional-binding decorator (pytest.mark.parametrize, click.argument, and the like) draws nothing, since the decorator may hand values to the parameters by slot. The self and cls receivers and the positional-only parameters before the / hold their place regardless, so they never count toward the disorder. The lint is non-rewriting, so the diagnostic surfaces without touching the source.

Configuration

KeyTypeDefaultMeaning
enabledbooltrueToggle the rule on or off

The keyword-only block past the * is a separate matter. A keyword-only parameter binds by name at every call site, so reordering it is always behavior-preserving, and

sorts it as an auto-fix rather than reporting it here.

The Canonical Case

A module-level function whose positional-or-keyword parameters sit out of alphabetical order draws a report-only diagnostic. The rule never reorders them, because doing so would rebind every positional call site, so it points the reorder out and leaves the call where the author can weigh the callers.

python
def merge(target, source, fallback=None):
    return target

More Examples

For per-line opt-outs, the Suppression chapter covers the # prose: ignore[unsorted-parameters] directive.