Skip to content

Commit f578d03

Browse files
committed
Improve formatting of type casts in parentheses.
1 parent 10231d8 commit f578d03

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Bug Fixes
2323
* Fix parsing error when using square bracket notation (issue583).
2424
* Fix splitting when using DECLARE ... HANDLER (issue581).
2525
* Fix splitting of statements using CASE ... WHEN (issue580).
26+
* Improve formatting of type casts in parentheses.
2627

2728

2829
Release 0.3.1 (Feb 29, 2020)

sqlparse/filters/reindent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def _process_parenthesis(self, tlist):
112112
ttypes = T.Keyword.DML, T.Keyword.DDL
113113
_, is_dml_dll = tlist.token_next_by(t=ttypes)
114114
fidx, first = tlist.token_next_by(m=sql.Parenthesis.M_OPEN)
115+
if first is None:
116+
return
115117

116118
with indent(self, 1 if is_dml_dll else 0):
117119
tlist.tokens.insert(0, self.nl()) if is_dml_dll else None

tests/test_regressions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,9 @@ def test_issue489_tzcasts():
399399
p = sqlparse.parse('select bar at time zone \'UTC\' as foo')[0]
400400
assert p.tokens[-1].has_alias() is True
401401
assert p.tokens[-1].get_alias() == 'foo'
402+
403+
404+
def test_as_in_parentheses_indents():
405+
# did raise NoneType has no attribute is_group in _process_parentheses
406+
formatted = sqlparse.format('(as foo)', reindent=True)
407+
assert formatted == '(as foo)'

0 commit comments

Comments
 (0)