Skip to content

Preserve original names in external from-imports - #881

Open
ryanchou1994 wants to merge 1 commit into
python-rope:masterfrom
ryanchou1994:fix/preserve-external-import-name
Open

ryanchou1994 wants to merge 1 commit into
python-rope:masterfrom
ryanchou1994:fix/preserve-external-import-name

Conversation

@ryanchou1994

Copy link
Copy Markdown

Renaming a project binding imported from an external module currently rewrites the external name too. In #831, renaming the compatibility module's izip produces an import of a name that itertools does not provide.

Preserve the source name of an external from import and add or update its local alias instead. Imports of definitions within the project still rename together. Import positions come from the existing AST offset adapter, and module resolution is limited to matching names so unrelated invalid imports do not block the rename.

Fixes #831.

Tests cover builtin and external Python modules, existing aliases, conditional cross-module bindings, multiline/Unicode source, and an unrelated invalid import. This is limited to from imports; the existing behavior for module-qualified external references is unchanged.

  • Added regression tests (5 fail on the unchanged base; 2 are behavior controls)
  • Updated CHANGELOG.md

Validation: 104 rename tests pass. Full suites pass on macOS/Python 3.14 (2,155 passed, 7 skipped, 5 xfailed) and Linux/Python 3.12 (2,151 passed, 11 skipped, 5 xfailed); Black passes.

Copilot AI lite review requested due to automatic review settings September 20, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

Rename Field changes the import and adds a nonexistent name.

2 participants