summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2020-09-30 15:30:00 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2020-09-30 15:30:00 +0200
commitf578d03ef7a0d1b0f84c59c4699ee307e725fc9c (patch)
treef16fc65a026eb2940c442efd5d06d2ae9b6e37ff
parent10231d89d76cb467729fb7391c6a80938d6c5f76 (diff)
downloadsqlparse-f578d03ef7a0d1b0f84c59c4699ee307e725fc9c.tar.gz
Improve formatting of type casts in parentheses.
-rw-r--r--CHANGELOG1
-rw-r--r--sqlparse/filters/reindent.py2
-rw-r--r--tests/test_regressions.py6
3 files changed, 9 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c34c7b6..d8220d1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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)
diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py
index 2b0f106..2d68abb 100644
--- a/sqlparse/filters/reindent.py
+++ b/sqlparse/filters/reindent.py
@@ -112,6 +112,8 @@ class ReindentFilter:
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
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 648cc4a..13c752b 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -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)'