Skip to content

Keep trailing block comments with the preceding statement - #875

Open
RamiNoodle733 wants to merge 2 commits into
andialbrecht:masterfrom
RamiNoodle733:agent/keep-trailing-block-comments
Open

Keep trailing block comments with the preceding statement#875
RamiNoodle733 wants to merge 2 commits into
andialbrecht:masterfrom
RamiNoodle733:agent/keep-trailing-block-comments

Conversation

@RamiNoodle733

Copy link
Copy Markdown

Summary

StatementSplitter already 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.Multiline to the end-of-statement trailing token types so line and block comments behave consistently.

Example:

sqlparse.split("SELECT 1; /* trailing */\nSELECT 2;")

Before, the block comment became part of the second statement. With this change the result is:

["SELECT 1; /* trailing */", "SELECT 2;"]

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.

Copilot AI lite review requested due to automatic review settings August 11, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Multiline as an end-of-statement trailing token type in StatementSplitter.
  • 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.

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.

2 participants