Skip to content

Python · correctness

require-keyword-only-swap-prone-params

python:require-keyword-only-swap-prone-params

Swap-prone parameters with the same primitive type should be keyword-only.

Code
SARJ034
Default
error
Fix
none
Languages
python

Why

Callers can exchange semantically distinct positional values without a type-checking failure.

Fix

Insert `*` before the risky parameters and pass them by name at call sites.

Before / after

Executed by this rule’s unit tests.

Before

Source and target IDs are positional

service.py · focus
def move(source_id: str, target_id: str) -> None: ...

After

Source and target IDs are keyword-only

service.py · focus
def move(*, source_id: str, target_id: str) -> None: ...

Limits

  • Only high-risk groups of bare `str`, `int`, or `float` annotations are reported.
  • Tests, generated code, protocols, routes, CLI handlers, overrides, and conventional ordered pairs are excluded.

Formerly: kwonly-same-type-params