Skip to content

summary-effect-regression (MUT103)

Family: Mutation & State (MUT) · Heuristic · Opt-in · Severity error (a bug) · No automatic fix

Interprocedural mutation/escape/effect regression against saved summary snapshot.

Heuristic

This rule is heuristic: a premise of its claim can be open ("What a report states" lists them), so a report can be wrong about the code. It runs only when select or extend-select names its code or name. It has not been measured yet. See Rule Precision.

What it does

Compares the interprocedural side effects of every public function with the summary snapshot saved by heki snapshot --write (.heki-summary-snapshot.json at the project root), and reports functions that gained one of:

  • a mutated parameter (the function now changes an argument it receives);
  • an escaping parameter (an argument is now stored in an attribute, a container, a global, or a variable of an enclosing function);
  • a mutated self attribute;
  • an execution effect (blocking network / database / subprocess / filesystem I/O, sleeping, client allocation, database queries), including effects reached through callees.

This rule is opt-in: enable it with --extend-select MUT103 or extend-select = ["MUT103"].

What a report states

A report states that a public function now has a side effect (a changed or escaping parameter, a changed self attribute, or an execution effect) that its summary in the saved snapshot does not have.

Its premises:

  • Has the effect: the function's current summary has it. Open: a summary counts an effect on any path, and of any candidate implementation of a call.
  • New: the snapshot's summary of the function lacks it. Established.

Why is this bad?

A pull request that makes a widely used helper start mutating its argument, or start doing network I/O, often looks harmless in the diff of the helper and breaks callers far away. The snapshot makes such effect regressions visible in review, the way a lock file makes dependency changes visible.

Example

# snapshot taken while `add` was pure
def add(items: list[int], x: int) -> list[int]:
    return items + [x]

After an edit:

def add(items: list[int], x: int) -> list[int]:  # MUT103: `add` now mutates parameter `items`
    items.append(x)
    return items

The report is on the function's def line, which is also where a suppression comment goes.

If the new effect is intended, refresh the snapshot with heki snapshot --write and commit it. The refresh writes nothing while a file of the project cannot be read or parsed (it exits with 2): the snapshot would lose that module's entries. A module with a .pyi stub is recorded and compared with the parameter names of its .py file.

Fix safety

No automatic fix.

Options

  • lint.extend-select = ["MUT103"] enables the rule.
  • The snapshot lives at .heki-summary-snapshot.json; heki snapshot prints it without writing.