Don't export names from never-run branches, lambda walruses or deleted on the same line - #59
Merged
hakancelikdev merged 1 commit intoSep 25, 2026
Conversation
…d on the same line - `if False:` / `if 0:` bodies and the else of `if True:` / `if not TYPE_CHECKING:` don't run at import time either. - A walrus inside a lambda binds a local of the lambda. - `X = 1; del X` compared line numbers only, so the del did not count; bindings and deletions are now ordered by (line, column). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
hakancelikdev
merged commit Sep 25, 2026
a465c6e
into
claude/issuelari-gorme-fpbbfd
26 checks passed
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.
Follow-up to #51 (issue #40), from the second review of the integration branch. In each of these cases the name was added to
__all__, sofrom m import *raisedAttributeError.Problems
X = 1; del X: thedelhandling compared line numbers only, so adelon the same line as the binding didn't count.if False:/if 0:blocks were treated as running code. This is the older type-checking idiom, still used in e.g. stdlib_pyrepl/pager.py. The same applied to theelseofif True:/if not TYPE_CHECKING:.f = lambda: (Y := 1):_rule_parent_not_defdidn't stop atast.Lambda, although_ModuleBindings.collectalready did.Fix
(line, column)(_position).relate._truth_on_importgives the static value of aniftest at import time.TYPE_CHECKINGand the main guard areFalse; constants have their own value;notinverts; anything else is unknown.is_runtime_missingthen marks the body of a false test and theelseof a true one.ast.Lambdais added to the ancestors in_rule_parent_not_def.Tests
Three new tests in
AnalyzerRuntimeNamesTestCase(same-linedel, constant/not TYPE_CHECKINGbranches, lambda walrus) fail before this change. 3.10 / 3.12 / 3.14, pre-commit, mypy and the self-check all pass.🤖 Generated with Claude Code
https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
Generated by Claude Code