Skip to content

fix(resolution): resolve line-wrapped Python parenthesized import lists - #1517

Open
JacquesBLR wants to merge 1 commit into
colbymchenry:mainfrom
JacquesBLR:fix-multiline-python-imports
Open

fix(resolution): resolve line-wrapped Python parenthesized import lists#1517
JacquesBLR wants to merge 1 commit into
colbymchenry:mainfrom
JacquesBLR:fix-multiline-python-imports

Conversation

@JacquesBLR

Copy link
Copy Markdown

Summary

extractPythonImports re-parses raw source text with a regex, separate from the tree-sitter AST. The regex [^#\n]+ stopped at the first newline, so a PEP 8 line-wrapped from pkg import (a,\n b) list lost every name after the statement's first physical line — not just aliased ones, the ImportMapping never existed at all for those names.

Found while running CodeGraph on a real project whose imports wrap this way; reproduces with as few as two names split across two lines.

Fix

fromImportRegex now matches either a parenthesized list ([\s\S]*? up to the closing paren, so it spans newlines) or the existing single-line form, and the capture group used depends on which branch matched.

Test plan

  • Added a regression test with two unaliased names split across a wrapped from pkg import (...) list, asserting both resolve (not just the first or last name)
  • Full test suite green: 2752 passed, 175 skipped, 0 failed

extractPythonImports re-parses raw source text with a regex, separate
from the tree-sitter AST. The regex `[^#\n]+` stopped at the first
newline, so a PEP 8 line-wrapped `from pkg import (a,\n b as c)` list
lost every name after the statement's first physical line entirely —
not just aliased ones, the mapping never existed at all. Found while
running CodeGraph on a real project whose imports wrap this way;
reproduces with as few as two names split across two lines.
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