fix(resolution): resolve line-wrapped Python parenthesized import lists - #1517
Open
JacquesBLR wants to merge 1 commit into
Open
fix(resolution): resolve line-wrapped Python parenthesized import lists#1517JacquesBLR wants to merge 1 commit into
JacquesBLR wants to merge 1 commit into
Conversation
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.
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.
Summary
extractPythonImportsre-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-wrappedfrom pkg import (a,\n b)list lost every name after the statement's first physical line — not just aliased ones, theImportMappingnever 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
fromImportRegexnow 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
from pkg import (...)list, asserting both resolve (not just the first or last name)