Skip to content

ChangeImport: rewrite qualified references when old_name is specified#6760

Merged
knutwannheden merged 1 commit intomainfrom
crisp-tapir
Feb 19, 2026
Merged

ChangeImport: rewrite qualified references when old_name is specified#6760
knutwannheden merged 1 commit intomainfrom
crisp-tapir

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

Summary

  • When old_name is set, ChangeImport now also rewrites qualified references (X.name()Y.name()) and manages direct imports (import Ximport Y)
  • Supports aliased imports (import X as f / f.name()import Y / Y.name())
  • Updates type attribution on rewritten nodes (Identifier._type, MethodInvocation._method_type)
  • Fixes pre-existing bugs in AddImport (insertion point) and RemoveImport (usage collection) for standalone Import nodes

Test plan

  • 5 new tests covering qualified method calls, aliased imports, retained imports, field access, and different new names
  • All 10 test_change_import tests pass
  • All 23 recipe tests pass (no regressions)

Comment thread rewrite-python/rewrite/src/rewrite/python/recipes/change_import.py
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Feb 18, 2026
@knutwannheden knutwannheden changed the title ChangeImport: rewrite qualified references when old_name is specified ChangeImport: rewrite qualified references when old_name is specified Feb 19, 2026
@knutwannheden knutwannheden force-pushed the crisp-tapir branch 3 times, most recently from 8de96ff to f6df7b1 Compare February 19, 2026 09:13
@knutwannheden knutwannheden changed the title ChangeImport: rewrite qualified references when old_name is specified ChangeImport: rewrite qualified references when old_name is specified Feb 19, 2026
When old_name is set, ChangeImport now also handles the `import X` /
`X.name()` pattern by rewriting qualified references and managing direct
imports. Supports aliased imports (`import X as f` / `f.name()`).

Type attribution is updated on rewritten nodes (Identifier._type,
MethodInvocation._method_type).

Also fixes two pre-existing bugs:
- AddImport: insertion point now considers standalone Import nodes
- RemoveImport: UsageCollector now skips standalone Import identifiers
@knutwannheden knutwannheden merged commit fcbe88b into main Feb 19, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Feb 19, 2026
@knutwannheden knutwannheden deleted the crisp-tapir branch February 19, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants