Skip to content

Preserve imports referenced by quoted type annotations - #969

Open
Aschenbath wants to merge 1 commit into
python-rope:masterfrom
Aschenbath:codex/oss20d-20261122-rope-string-annotations
Open

Aschenbath wants to merge 1 commit into
python-rope:masterfrom
Aschenbath:codex/oss20d-20261122-rope-string-annotations

Conversation

@Aschenbath

Copy link
Copy Markdown

Imports used only in quoted annotations are currently removed by Organize Imports, including from foo import Baz followed by value: "Baz".

Parse annotation strings as AST expressions without evaluating them and collect their referenced names. Cover variable, class, synchronous/asynchronous function signatures and nested generic annotations. Signature annotations are inspected in their enclosing scope. Ordinary strings, invalid annotation text, and strings in conventionally named Literal values / Annotated metadata do not retain imports.

Validation: the initial regression fails before the fix; 157 import utility tests and 249 related move/extract tests pass (one skip and one expected failure). Black and isort checks pass. Existing deprecation/syntax warnings remain. This does not implement general type inference or resolve aliases of Literal and Annotated.

Fixes #369.

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.

ImportOrganizer should not remove imports used in string type annotation

1 participant