Fix false dependency from a class to a same-named outer constant#45
Merged
Conversation
5ed544b to
2500b3d
Compare
…definition An enum member or class variable named like the module constant that aliases it forged a false class->constant edge, closing a cycle that hoisted the constant above the class it references (NameError at import). A name bound in a class's own body is now recognized as that class's own namespace and imposes no ordering on outer definitions. Also make every test_files fixture self-contained and side-effect free, and replace the parse-only guard with test_fixture_files_execute, which runs each input and output file in a fresh namespace. This catches a fixture that parses but does not run -- exactly the failure mode of an unsorted input or a codemod output that hoists a definition above one it depends on. Six fixtures that referenced undefined names or mutated global state (sys.path, __file__) were rewritten to valid, runnable equivalents and their outputs regenerated.
2500b3d to
981e04f
Compare
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.
Found while rolling codesorter out to
bboe/update_checker, whosecore.pyimport broke with aNameError.The bug
An enum member (or class variable) named like the module constant that aliases it:
_get_dependencies(_Sentinel)matched the class-body bindingCACHE_MISSand resolved it to the module-level constant, forging a false_Sentinel->CACHE_MISSedge. Combined with the realCACHE_MISS->_Sentineledge that is a cycle, and cycle-breaking releases the lowest-keyed node (the constant) first — hoisting it above the class it references.The fix
A name bound at a class's own body level belongs to that class's namespace, so it imposes no ordering on an outer definition of the same name. The guard is scoped to
name_scope.node == nodeso a name bound in the enclosing class (a sibling method that analias = methodassignment references) is still a real dependency —test_alias_functioncovers that and stays green.Verification
enum_member_alias+test_enum_member_alias; full suite (28) green, pyright clean.bboerollout repos (update_checker, sbmod, reclaude, deslackify, flask-image-uploader, extended_http_server): every one sorts to valid syntax and isF821(undefined-name) clean. update_checker now orders_SentinelbeforeCACHE_MISSand its 42 tests pass. No other rollout-breaking issues surfaced.