Keep trailing block comments with the preceding statement - #875
Open
RamiNoodle733 wants to merge 2 commits into
Open
Keep trailing block comments with the preceding statement#875RamiNoodle733 wants to merge 2 commits into
RamiNoodle733 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request updates StatementSplitter so that block (multiline) comments immediately following a statement terminator are treated as trailing content of the preceding statement—matching the existing behavior for whitespace and single-line comments. This aligns splitting behavior with how formatted/parsed output is typically expected to preserve post-semicolon comments with the statement they logically annotate.
Changes:
- Treat
T.Comment.Multilineas an end-of-statement trailing token type inStatementSplitter. - Add regression tests ensuring trailing block comments stay with the preceding statement and remain consistent with single-line trailing comments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sqlparse/engine/statement_splitter.py |
Extends end-of-statement trailing token classification to include multiline comments. |
tests/test_split_trailing_comments.py |
Adds targeted regression tests for trailing block comments and consistency with existing single-line comment behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
StatementSplitteralready treats whitespace and single-line comments after a statement terminator as trailing content for that statement, but multiline comments were handled differently. A block comment immediately after a semicolon was therefore attached to the following SQL statement instead of the statement it followed.This change adds
T.Comment.Multilineto the end-of-statement trailing token types so line and block comments behave consistently.Example:
Before, the block comment became part of the second statement. With this change the result is:
Regression tests cover the block-comment case and consistency with existing single-line comment behavior.
Validation
I could not run the project test suite in this execution environment because a local checkout/dependency environment was unavailable. The branch is based directly on current upstream
master, and the diff is limited to the splitter token classification plus focused regression tests.