Skip to content

Commit

Permalink
Improve formatting of type casts in parentheses.
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Sep 30, 2020
1 parent 10231d8 commit f578d03
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Bug Fixes
* Fix parsing error when using square bracket notation (issue583).
* Fix splitting when using DECLARE ... HANDLER (issue581).
* Fix splitting of statements using CASE ... WHEN (issue580).
* Improve formatting of type casts in parentheses.


Release 0.3.1 (Feb 29, 2020)
Expand Down
2 changes: 2 additions & 0 deletions sqlparse/filters/reindent.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def _process_parenthesis(self, tlist):
ttypes = T.Keyword.DML, T.Keyword.DDL
_, is_dml_dll = tlist.token_next_by(t=ttypes)
fidx, first = tlist.token_next_by(m=sql.Parenthesis.M_OPEN)
if first is None:
return

with indent(self, 1 if is_dml_dll else 0):
tlist.tokens.insert(0, self.nl()) if is_dml_dll else None
Expand Down
6 changes: 6 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,9 @@ def test_issue489_tzcasts():
p = sqlparse.parse('select bar at time zone \'UTC\' as foo')[0]
assert p.tokens[-1].has_alias() is True
assert p.tokens[-1].get_alias() == 'foo'


def test_as_in_parentheses_indents():
# did raise NoneType has no attribute is_group in _process_parentheses
formatted = sqlparse.format('(as foo)', reindent=True)
assert formatted == '(as foo)'

0 comments on commit f578d03

Please sign in to comment.