Don't add names that are bound in only one branch of an undecidable if - #64
Merged
hakancelikdev merged 2 commits intoSep 25, 2026
Merged
Conversation
`if sys.platform == "win32": class WinOnly: ...` added WinOnly to __all__, so `from module import *` failed on every other platform. A name is only added when every branch of such an if binds it (following elif chains). Listed names are still kept and `# unexport: public` still adds one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
…nto fix/conditional-names # Conflicts: # docs/changelog.md
hakancelikdev
merged commit Sep 25, 2026
6eb851e
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.
From the core-dev review of the integration branch. The problem also exists on
main.Problem
WinOnlywas added to__all__, sofrom module import *raisedAttributeErroron every other platform. Stdlib modules such asctypes,subprocess,selectorsandmultiprocessing.*follow this pattern.Fix
relate.is_conditional_onlyand rule_rule_not_conditional_only.ifwhose test can't be decided statically. Tests that can be decided (TYPE_CHECKING, the main guard, constants) are already handled byis_runtime_missing.elifchains are followed: each level must bind the name in the other branch. A binding can be an assignment,def/classor import.# unexport: publicstill adds a name explicitly.This is a behavior change: a name defined only inside e.g.
if HAS_NUMPY:is no longer added automatically. I chose this conservative default because adding it produces an__all__that breaks star imports on the other branch.try/except ImportErrorbodies are left as they were.Tests
test_names_bound_in_one_branch_onlycovers if/elif/else binding in every branch, a def vs an assignment, an import in the other branch, and the# unexport: publicoverride. It fails before this change.test_listed_conditional_name_is_keptcovers an already-listed conditional name.🤖 Generated with Claude Code
https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
Generated by Claude Code