summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2020-03-01 20:12:17 (GMT)
committerGitHub <noreply@github.com>2020-03-01 20:12:17 (GMT)
commit397b96f6d7a89f778ebc0591e32216a8183fe667 (patch)
treebca7cb5940e1a5cb1cdc80b3578a238dfac318d1 /Lib/test/test_ast.py
parent185903de12de8837bf0dc0008a16e5e56c66a019 (diff)
downloadcpython-397b96f6d7a89f778ebc0591e32216a8183fe667.zip
cpython-397b96f6d7a89f778ebc0591e32216a8183fe667.tar.gz
cpython-397b96f6d7a89f778ebc0591e32216a8183fe667.tar.bz2
bpo-38870: Implement a precedence algorithm in ast.unparse (GH-17377)
Implement a simple precedence algorithm for ast.unparse in order to avoid redundant parenthesis for nested structures in the final output.
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 2ed4657..e788485 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -247,6 +247,13 @@ eval_tests = [
class AST_Tests(unittest.TestCase):
+ def _is_ast_node(self, name, node):
+ if not isinstance(node, type):
+ return False
+ if "ast" not in node.__module__:
+ return False
+ return name != 'AST' and name[0].isupper()
+
def _assertTrueorder(self, ast_node, parent_pos):
if not isinstance(ast_node, ast.AST) or ast_node._fields is None:
return
@@ -335,7 +342,7 @@ class AST_Tests(unittest.TestCase):
def test_field_attr_existence(self):
for name, item in ast.__dict__.items():
- if isinstance(item, type) and name != 'AST' and name[0].isupper():
+ if self._is_ast_node(name, item):
x = item()
if isinstance(x, ast.AST):
self.assertEqual(type(x._fields), tuple)