Unwrap leading parenthesis in Statement.get_type() (fixes #727) - #877
Open
ChrisJr404 wants to merge 1 commit into
Open
Unwrap leading parenthesis in Statement.get_type() (fixes #727)#877ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
A parenthesized statement, such as one side of a compound query like (SELECT ...) UNION (SELECT ...), previously reported its type as UNKNOWN because get_type() only inspected the outer Parenthesis token. Unwrap a leading parenthesis (including nested ones) before matching the DML/DDL/CTE keyword, so the keyword inside the parentheses determines the statement type. Empty parentheses still report UNKNOWN. Fixes andialbrecht#727
ChrisJr404
force-pushed
the
fix/get-type-parenthesized-issue727
branch
from
August 18, 2026 20:37
3a8f362 to
880d2d6
Compare
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.
Fixes #727.
Statement.get_type()only looked at the first significant token. When astatement is wrapped in parentheses, that token is the whole
Parenthesisgroup rather than a DML/DDL keyword, so the type came back as
UNKNOWN:Parenthesized sub-selects like this (e.g. the sides of a compound
UNION)are common, so it is surprising that only the un-parenthesized form is
recognized.
Change
get_type()now unwraps a leading parenthesis before matching the keyword.The loop handles nested parentheses (
((select 1))) and skips the openingpunctuation together with any whitespace/comments inside. The existing CTE
handling now runs against the unwrapped container, so a
WITHwrapped inparentheses resolves too. Empty parentheses still report
UNKNOWN.Tests
Added
test_gettype_parenthesized_statement_issue727covering the reportedcase plus nesting, a non-SELECT keyword, a leading comment, a parenthesized
CTE, and the empty-parentheses guard. The full suite passes (
pytest), andruff checkis clean on the changed module.