fix: handle missing 'import' keyword in break_up_import - #346
Closed
frankgoldfish wants to merge 1 commit into
Closed
fix: handle missing 'import' keyword in break_up_import#346frankgoldfish wants to merge 1 commit into
frankgoldfish wants to merge 1 commit into
Conversation
When source code contains carriage returns (\r) within parenthesized import statements, Python's io.StringIO.readlines() may produce continuation lines that don't contain the 'import' keyword. In such cases, re.split(r'\bimport\b', line) returns a list with only one element, causing a ValueError when trying to unpack to (indentation, imports). Fix: check the length of parts returned by re.split in break_up_import. If 'import' is not found in the line, return the line unchanged. Fixes #326
Author
|
Closing this PR — found that PR #328 already addresses this issue. Apologies for the duplicate. |
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.
Problem
When source code contains carriage returns (`\r`) within parenthesized import statements,
io.StringIO.readlines()may produce continuation lines that don't contain theimportkeyword. Whenbreak_up_import()is called on such a line,re.split(r'\bimport\b', line)returns only one element, and unpacking to(indentation, imports)raises:Reproducible with:
Fix
In
break_up_import(), check the number of parts returned byre.split(). If'import'is not found in the line (i.e., it's a bare continuation line), return the line unchanged.Tests
Added
TestCarriageReturnInImporttest class verifying the fix.Fixes #326