Upstream andialbrecht/sqlparse state of the touched files before 730ddba559

This commit is contained in:
upstream committed 2026-09-02 12:14:20 +02:00
1 parent 241869a841
commit 46e6a17daf
4 files changed
+1526 -22

No files matched your search

+1 -22
View File
@@ -309,34 +309,13 @@ def group_operator(tlist):
def group_identifier_list(tlist):
m_role = T.Keyword, ('null', 'role')
m_to = T.Keyword, 'TO'
sqlcls = (sql.Function, sql.Case, sql.Identifier, sql.Comparison,
sql.IdentifierList, sql.Operation)
ttypes = (T_NUMERICAL + T_STRING + T_NAME
+ (T.Keyword, T.Comment, T.Wildcard))
def is_rename_separator(token):
# In ``RENAME TABLE a TO b, c TO d`` the comma separates independent
# rename clauses, so the target of one clause (``b``) and the source
# of the next (``c``) must not be merged into a single IdentifierList.
# Detect that layout by the ``TO`` keywords flanking both sides of the
# comma and leave such a comma ungrouped (issue779).
parent = token.parent
if parent is None:
return False
cidx = parent.token_index(token)
pidx, prev_ = parent.token_prev(cidx)
nidx, next_ = parent.token_next(cidx)
if prev_ is None or next_ is None:
return False
_, before_prev = parent.token_prev(pidx)
_, after_next = parent.token_next(nidx)
return (before_prev is not None and before_prev.match(*m_to)
and after_next is not None and after_next.match(*m_to))
def match(token):
return token.match(T.Punctuation, ',') \
and not is_rename_separator(token)
return token.match(T.Punctuation, ',')
def valid(token):
return imt(token, i=sqlcls, m=m_role, t=ttypes)