Repository navigation
fix(names): a module's name is unbound until its assignment runs - #236
Merged
Merged
Conversation
Every name a module assigns was declared as None before the first statement, so `"x" in globals()` was True ahead of `x = 1` and a read there answered None where CPython raises NameError. Those names now start as %py-deleted, and a read of one goes through the NameError check only where it is not bound for certain (%py-bound-now, which now keeps the module's names too); after an unconditional assignment the read is the bare symbol it was. `None += 1` names None, which reads as its value: the target list keeps symbols only, or hoisting it unbinds None itself. Makes basics/annotate_var pass and retires B2-scoping's divergence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A module's assigned names were declared as None before its first statement, so
"x" in globals()was True ahead ofx = 1, and readingxthere gave None instead of NameError. This was the cause ofbasics/annotate_var. The bare annotation itself was already a no-op; the program assignsxfurther down.%py-deleted).%py-declsinpython/parse.xdoes this.%py-name-livecheck only where the name is not bound for certain. That reuses%py-bound-now, which now keeps the module's names as well as a def's. Reads after an unconditional top-level assignment, including those in defs written after it, stay bare symbols. A binding the analysis misses costs a check, never a wrong answer.None += 1puts None's value in the target list, so the list keeps symbols only. Without that, hoisting it unbinds None for the whole process (exit 139 in10-assign).Tests:
07-nameshas two new cases, with output from CPython 3.14:globals()before and after assignment; NameError for an early read, anif False:assignment, and a def called before its global exists.B2-scoping's annotation case had stated the old behaviour as a DIVERGENCE. It now expects CPython's False/True.Verified on v0.55.0:
basics/annotate_varpasses.🤖 Generated with Claude Code