Skip to content

Don't export names from never-run branches, lambda walruses or deleted on the same line - #59

Merged
hakancelikdev merged 1 commit into
claude/issuelari-gorme-fpbbfdfrom
fix/runtime-missing-edge-cases
Sep 25, 2026
Merged

hakancelikdev merged 1 commit into
claude/issuelari-gorme-fpbbfdfrom
fix/runtime-missing-edge-cases

Conversation

@hakancelikdev

Copy link
Copy Markdown
Owner

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__, so from m import * raised AttributeError.

Problems

  1. X = 1; del X: the del handling compared line numbers only, so a del on the same line as the binding didn't count.
  2. 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 the else of if True: / if not TYPE_CHECKING:.
  3. f = lambda: (Y := 1): _rule_parent_not_def didn't stop at ast.Lambda, although _ModuleBindings.collect already did.

Fix

  • Bindings and deletions are ordered by (line, column) (_position).
  • relate._truth_on_import gives the static value of an if test at import time. TYPE_CHECKING and the main guard are False; constants have their own value; not inverts; anything else is unknown. is_runtime_missing then marks the body of a false test and the else of a true one.
  • ast.Lambda is added to the ancestors in _rule_parent_not_def.

Tests

Three new tests in AnalyzerRuntimeNamesTestCase (same-line del, constant/not TYPE_CHECKING branches, 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

…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
hakancelikdev merged commit a465c6e into claude/issuelari-gorme-fpbbfd Sep 25, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants