Skip to content

state_mutation: python, embedded_python and ruby never count a plain re-assignment (narrower than the #2765 contract) #2817

Closed

Description

@squid-protocol

Found by the state_mutation contract audit (#2765, docs/state_mutation_rule_contract.md).

The contract says one hit is a statement that writes a new value into state that already exists, and corollary 1's fallback says that where a language has no declaration syntax the assignment statement is the only write form there is, so it counts. shell, php, powershell, tcl, livecode, matlab, fortran, groovy and lua (for non-local names) all read that way.

python and embedded_python do not. Their rule counts self.x = v, global/nonlocal, :=, and the container mutators (.append(, .update(...), and never a plain x = v:

count = count + 1        # lua: 1, php: 1, shell: 1, go: 1 -- python: 0
self.count = count + 1   # python: 1

ruby is the same for locals (its rule counts @ivar =, @@cvar =, mutators and bang methods).

Both read 2 on the keyword-rosetta corpus because the plants are container writes, which are writes, so nothing is red -- but the same construct is scored in one language and invisible in the next, which is exactly the inequality #2812 exists to remove. The contract doc records python/ruby as narrower than the contract, deferred.

Why it is not in the #2765 PR: the fix is one arm per rule (a statement-start x = v with the kwargs/default-parameter shapes excluded -- black-formatted code puts spaces around a statement's = and none around a keyword argument's, which is the usable anchor), but python is the engine's most-scanned language and risk_state_flux for every python file in the telemetry population reprices. That deserves its own golden-master review, a crucible incidence table for the kwargs/multi-line-call false positives, and its own corpus re-bless, not a line inside a 30-language PR.

To do: the arm, strict tests for x = 1 / foo(x=1) / def f(x=1) / x == 1 / x: int = 1, the same for embedded_python and ruby locals, and a row update in docs/state_mutation_rule_contract.md moving the three from deferred to agrees.

Part of #2812 (Phase 3).

Activity

  1. added
    metrics
    core-engine
    on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-enginemetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions