Repository navigation
Preserve imports shadowed by inherited class attributes - #958
Open
ViktorBystrov72 wants to merge 1 commit into
Open
ViktorBystrov72 wants to merge 1 commit into
ViktorBystrov72 wants to merge 1 commit into
Conversation
This branch has not been deployed
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
Import cleanup removes a required import when a base class defines an attribute with the same name. In the example from #244,
from foo import baris needed bybaz = barin a subclass body. Python resolves that bare name outside the class; it does not read the inherited attribute. The generated module currently raisesNameError.Use the names defined in the class when checking whether an import is shadowed there. Propagated-name lookup remains unchanged. Regression tests cover from-imports, dotted module imports, and an actual class-local binding that still makes an import unused.
Fixes #244
Validation
git diff --checkpass.ImportOrganizerAPI executes the issue's example in temporary directories: the original program prints10, the unmodified refactoring result raisesNameError, and the corrected result prints10.The first full run used uv's Python 3.13.13, whose
_sqlite3module is built in and has no__file__. That run had 2,182 passed, 7 skipped, 5 xfailed and one error in the existing compiled-library fixture. The same fixture error reproduces on untouched master. The complete passing run above uses Homebrew's dynamic_sqlite3extension; no tests were disabled or modified to bypass it.Checklist
AI assistance
OpenAI Codex assisted with issue and source analysis, implementation, regression tests, local verification, and this description. The change was checked against the source and validated with the tests and public API reproducer listed above.