Skip to content

Fall back to module bindings for star-import suggestions when __all__ is partly dynamic - #365

Merged
hakancelikdev merged 1 commit into
claude/integrationfrom
fix/partial-dunder-all
Sep 25, 2026
Merged

hakancelikdev merged 1 commit into
claude/integrationfrom
fix/partial-dunder-all

Conversation

@hakancelikdev

Copy link
Copy Markdown
Owner

Regression from #345 (__all__ += support), found in the second review of claude/integration.

Problem

# lib.py
import core
from core import alpha
__all__ = list(core.__all__)
__all__ += ["beta"]
beta = 2
# user.py
from lib import *
print(alpha, beta)

Only beta was read from __all__. Because that list was not empty, the fallback to the module's bindings was skipped, and --include-star-import rewrote the import to from lib import beta, which raises NameError on alpha. main suggested alpha, beta.

Fix

ImportableNameAnalyzer.is_dynamic is set when any __all__ assignment, augmented assignment (non-+), item, append/extend argument or other method call can't be read statically. In that case iget_importable_name yields the literal names and the module's bindings. extend now also accepts tuples and sets, through the shared _add_items.

Tests

test_star_import_suggestions_with_partly_dynamic_all fails before this change. Full suite passes on 3.9 / 3.12 / 3.14, and pre-commit passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V


Generated by Claude Code

… is partly dynamic

With `__all__ = list(core.__all__)` followed by `__all__ += ["beta"]`, only
the literal part was known, and because it was not empty the fallback to the
module's bindings was skipped. Rewriting `from lib import *` then dropped
names that are used. Any non-literal __all__ assignment, item or method call
now marks it dynamic, and the module's bindings are suggested as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
@hakancelikdev
hakancelikdev merged commit 70f3a87 into claude/integration Sep 25, 2026
40 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