Skip to content

python/parameter-alias

Pack Severity Fix Versions
Python warning none, edit by hand All versions

Accepting two parameter names for the same input and falling back from one to the other keeps a legacy parameter alias alive in your API. Keep one canonical parameter name and update callers.

def load_orders(path: str | None = None, *, file_path: str | None = None) -> str:
path = path if path is not None else file_path
return str(path)
def load_orders(path: str) -> str:
return path

The rule reports three forms of parameter aliasing inside a function:

  • Falling back from one formal parameter to another (path = path or old_path, path = path if path is not None else old_path, or if path is None: path = old_path).
  • Falling back from a formal parameter to kwargs.pop("old_name", ...) on the function's **kwargs parameter.
  • Chaining kwargs.pop("new_name", None) or kwargs.pop("old_name", ...) across two different string keys on the same mapping.

The rule leaves alone default-value fallbacks against a module constant or function call (path = path or DEFAULT_PATH), and standalone kwargs.pop("timeout", 30) option stripping when no parameter alias is involved.

xpd has no automatic fix, so make the change by hand.

Delete the legacy parameter or kwargs.pop fallback, keep one canonical parameter name in the signature, and update every caller in the same commit.

Falling back from parameter $P1 to parameter $P2 keeps a legacy parameter alias alive. Keep one canonical parameter name and update callers.

See all rules in the Python pack.