From f578d03ef7a0d1b0f84c59c4699ee307e725fc9c Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Wed, 30 Sep 2020 15:30:00 +0200 Subject: Improve formatting of type casts in parentheses. --- CHANGELOG | 1 + sqlparse/filters/reindent.py | 2 ++ tests/test_regressions.py | 6 ++++++ 3 files changed, 9 insertions(+) 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)' -- cgit v1.2.1