Repository navigation
Keep star imports when inlining a function or method - #940
Merged
Merged
Conversation
RemovePyNameVisitor rebuilt every from-import from the names it kept. For a star import no names were collected, so the import was replaced by an empty one and dropped, breaking other names it provided. Leave star imports unchanged. Fixes python-rope#826
lieryan
approved these changes
Nov 13, 2026
lieryan
enabled auto-merge
November 13, 2026 20:09
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #940 +/- ##
=======================================
Coverage 95.44% 95.44%
=======================================
Files 134 134
Lines 26896 26902 +6
=======================================
+ Hits 25671 25677 +6
Misses 1225 1225 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Thanks for looking into this issue. @allcontributors please add @chinghar for code contribution |
Contributor
|
I've put up a pull request to add @chinghar! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Inlining a function or method removed any star import (
from x import *) in themodules where the call sites were inlined, breaking other names those imports provided.
Root cause: after inlining,
_remove_from()runsRemovePyNameVisitorover themodule's imports to drop the now-unused import of the inlined name.
visitFromImportrebuilds each from-import from the names it keeps, but for starimports it collected none, so the import was replaced with an empty
FromImportand dropped. The visitor now leaves star imports unchanged.
Reproduction (before this change):
Inlining
A.fproducedmod2.pywithoutfrom os import *. It is now kept.Test: added
test_inlining_method_keeps_star_imports_in_the_dest_moduletoropetest/refactor/inlinetest.py; it fails before the change and passes after.Full suite: 2167 passed, 7 skipped, 5 xfailed. pre-commit (black, isort) passes.
Fixes #826
Checklist (delete if not relevant):