Preserve blank lines between pre-import code and first import#441
Closed
Childcity wants to merge 1 commit into
Closed
Preserve blank lines between pre-import code and first import#441Childcity wants to merge 1 commit into
Childcity wants to merge 1 commit into
Conversation
Previously, blank lines (NON_CODE tokens) that appeared between the last pre-import block (docstring, shebang, encoding comment) and the first import statement were silently dropped by partition_source(). This was inconsistent with Black, which keeps such blank lines intact. Root cause: the loop building pre/imports/code only added NON_CODE chunks to 'code' when i > last_idx. Blank lines before last_idx were simply discarded. Fix: track last_pre_import_idx (index of the last PRE_IMPORT_CODE chunk) and first_import_idx (index of the first IMPORT chunk). NON_CODE chunks that fall strictly between those two positions are now appended to 'pre', preserving the original blank lines. Blank lines between pre-import comments (before the docstring boundary) are still stripped, as are blank lines between import statements themselves -- only the gap between the pre-import block and the first import is preserved.
Repository owner
locked as spam and limited conversation to collaborators
Jun 12, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Previously, blank lines (NON_CODE tokens) that appeared between the last pre-import block (docstring, shebang, encoding comment) and the first import statement were silently dropped by partition_source().
This was inconsistent with Black, which keeps such blank lines intact.
Root cause: the loop building pre/imports/code only added NON_CODE chunks to 'code' when i > last_idx. Blank lines before last_idx were simply discarded.
Fix: track last_pre_import_idx (index of the last PRE_IMPORT_CODE chunk) and first_import_idx (index of the first IMPORT chunk). NON_CODE chunks that fall strictly between those two positions are now appended to 'pre', preserving the original blank lines.
Blank lines between pre-import comments (before the docstring boundary) are still stripped, as are blank lines between import statements themselves -- only the gap between the pre-import block and the first import is preserved.