You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
state_mutation: python, embedded_python and ruby never count a plain re-assignment (narrower than the #2765 contract) #2817
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:
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.
Activity
feat(contracts): state_mutation gets a stated contract -- a statement…