From 822f04c7e2d7c4c3bdf1879ad578f94491d3c6bf Mon Sep 17 00:00:00 2001 From: Rami Abdelrazzaq Date: Tue, 11 Aug 2026 10:08:59 -0500 Subject: [PATCH 1/2] Keep trailing block comments with preceding statement --- sqlparse/engine/statement_splitter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sqlparse/engine/statement_splitter.py b/sqlparse/engine/statement_splitter.py index bc57d170..c3e637d0 100644 --- a/sqlparse/engine/statement_splitter.py +++ b/sqlparse/engine/statement_splitter.py @@ -150,14 +150,13 @@ def _change_splitlevel(self, ttype, value): def process(self, stream): """Process the stream""" - EOS_TTYPE = T.Whitespace, T.Comment.Single + EOS_TTYPE = T.Whitespace, T.Comment.Single, T.Comment.Multiline # Run over all stream tokens for ttype, value in stream: # Yield token if we finished a statement and there's no whitespaces # It will count newline token as a non whitespace. In this context # whitespace ignores newlines. - # why don't multi line comments also count? if self.consume_ws and ttype not in EOS_TTYPE: yield sql.Statement(self.tokens) From 86506d7a051ba673c73404e11f5c61f03d4a4629 Mon Sep 17 00:00:00 2001 From: Rami Abdelrazzaq Date: Tue, 11 Aug 2026 10:09:22 -0500 Subject: [PATCH 2/2] Add regression test for trailing block comments --- tests/test_split_trailing_comments.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/test_split_trailing_comments.py diff --git a/tests/test_split_trailing_comments.py b/tests/test_split_trailing_comments.py new file mode 100644 index 00000000..3fe78a53 --- /dev/null +++ b/tests/test_split_trailing_comments.py @@ -0,0 +1,18 @@ +import sqlparse + + +def test_split_keeps_trailing_block_comment_with_statement(): + sql = "SELECT 1; /* trailing */\nSELECT 2;" + + assert sqlparse.split(sql) == [ + "SELECT 1; /* trailing */", + "SELECT 2;", + ] + + +def test_split_trailing_comments_are_consistent(): + block = "SELECT 1; /* trailing */\nSELECT 2;" + line = "SELECT 1; -- trailing\nSELECT 2;" + + assert sqlparse.split(block)[0] == "SELECT 1; /* trailing */" + assert sqlparse.split(line)[0] == "SELECT 1; -- trailing"