Skip to content

Preserve imports exported through literal __all__ additions - #1482

Open
sorinc03 wants to merge 1 commit into
Instagram:mainfrom
sorinc03:fix/gather-exports-method-calls
Open

sorinc03 wants to merge 1 commit into
Instagram:mainfrom
sorinc03:fix/gather-exports-method-calls

Conversation

@sorinc03

@sorinc03 sorinc03 commented Nov 2, 2026

Copy link
Copy Markdown

Summary

GatherExportsVisitor ignores literal __all__.append() and .extend() calls. Consequently, RemoveUnusedImportsCommand can delete an import that the module explicitly exports through one of those calls.

Recognize direct, unconditional module-level expression statements using literal strings or literal list/tuple additions. Structural receiver checks exclude indirect call/subscript receivers, and module-level call indexing excludes deferred/conditional expressions. Existing assignment gathering is preserved.

Refs #1481. This implements literal additions; removal remains conservative because unresolved additions or aliases can leave duplicate exported names. The full issue should remain open for sound removal analysis.

Test Plan

  • Against unchanged base, the two final regression methods fail in ten subcases covering missing export gathering and incorrectly deleted imports.
  • Final focused visitor/codemod tests: 28 pass.
  • Real RemoveUnusedImports regressions retain exported imports and preserve imports around unresolved additions/removals, aliases, conditionals, functions, lambdas and generators.
  • Full uv run poe test: 2,167 tests, no unexpected failures; 14 skips and two expected failures. Coverage 95.8%.
  • uv run poe format, uv run poe lint and uv run poe typecheck pass; diff check clean.
  • Python 3.11 with the repository's locally built Rust/native parser; no Rust source changes. Wider Python/platform matrix remains for CI.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant