Skip to content

Fix relative imports when renaming files#4241

Open
xaskii wants to merge 2 commits into
facebook:mainfrom
xaskii:xaskii/module-renaming-fix
Open

Fix relative imports when renaming files#4241
xaskii wants to merge 2 commits into
facebook:mainfrom
xaskii:xaskii/module-renaming-fix

Conversation

@xaskii

@xaskii xaskii commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4055

  • We resolve relative imports against the importing module when updating imports for willRenameFiles.
  • This fixes renames like pkg/a.py to pkg/a2.py, where from .a import foo should become from .a2 import foo.
  • If a move takes the module outside the package targeted by the leading dots, we update the import to an absolute path instead.

Test Plan

  • uv run --with jsonschema --with toml test.py
  • Added regression tests for renaming within a package and moving outside it.

@xaskii
xaskii force-pushed the xaskii/module-renaming-fix branch from b0dd9d7 to b25f253 Compare July 22, 2026 06:05
@github-actions github-actions Bot added size/l and removed size/l labels Jul 22, 2026
@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP WillRenameFiles implementation doesn't adjust relative imports

2 participants