Skip to content

Fix namespace package directory renames - #902

Open
yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix/namespace-package-renames
Open

yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix/namespace-package-renames

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown
Contributor

Description

I fixed directory renames for namespace packages without an __init__.py. Renaming a package such as valuespkg, imported with import valuespkg.foreign, currently raises RecursionError before producing changes: the local-name check asks the package for its scope, and the package delegates back to itself.

I now check local scope only for assigned names, which are the only names that can satisfy the existing local-variable predicate. A default project-wide namespace package rename updates imports and moves the directory together. With an explicit resource list, the directory moves only when all its project Python files are selected and there is at least one such file. Importer-only selections continue to update the selected files without moving the package; ordinary package and module move rules are preserved.

The regression tests exercise actual directory moves, saved module values, nested namespace packages with relative imports, import aliases, empty namespace packages, explicit resource limits, and ordinary package controls. Successful cases run before and after the rename and preserve an unrelated resource. This change is limited to Rename and does not introduce a general namespace package scope implementation.

Validation: the original six-case baseline fails in five namespace cases with RecursionError and passes the ordinary-package control on Python 3.12 and 3.14. The fix passes all ten regression tests and all 263 related Rename, Move, scope, and object-inference tests on both versions. Black, isort, the configured checks, and git diff --check pass. The complete suite passes on Python 3.12 (2159 passed, 12 skipped, 5 xfailed) and 3.14 (2163 passed, 8 skipped, 5 xfailed), with 2176 collected on each version.

Checklist

  • I have added tests that prove the fix is effective.
  • I have updated CHANGELOG.md.
  • I have documented the namespace package resource selection behavior.

@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.37%. Comparing base (22f5e50) to head (1bdbd95).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #902      +/-   ##
==========================================
+ Coverage   95.34%   95.37%   +0.03%     
==========================================
  Files         134      135       +1     
  Lines       26762    26896     +134     
==========================================
+ Hits        25516    25652     +136     
+ Misses       1246     1244       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant