refactor: stop mutating self.variables() in the one-variable shortcut#22
Merged
Conversation
Solver.__call__ extracted the sole variable name with set.pop() on the return value of self.variables(). Today that set is a fresh copy per call, so no harm is observable — but any future binding optimization that returns cached state would silently corrupt it. Use unpacking ((only_var,) = variables) so the set is never mutated. Regression test in tests/test_solver_one_var_shortcut_invariants.py asserts variables() is stable across the shortcut path. See ai/improvements_2026-05-09.md item #8. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem.
Solver.__call__extracted the sole variable name withset.pop()on the return value ofself.variables(). Today that set is a fresh copy per call (so no harm is observable), but any future binding optimization that caches or returns a reference would have the wrapper silently corrupt internal state.Fix.
src/formula/formula.py:69-70— use unpacking(only_var,) = variablesso the set is never mutated.Test.
tests/test_solver_one_var_shortcut_invariants.pypins the invariant:solver.variables()returns the same set before and after the shortcut path, across repeated calls.Full suite 319/319.