summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-02-12 20:56:44 (GMT)
committerGitHub <noreply@github.com>2020-02-12 20:56:44 (GMT)
commit2076d4f97ef514bb4dc4ca768fbaa3f538ce7f1f (patch)
tree27fd90f87bd5b18e4391ad498bde154c612228cf /Lib
parentac6f4d2db703c0ff88e496bcb7b7fe55cf2ac458 (diff)
downloadcpython-2076d4f97ef514bb4dc4ca768fbaa3f538ce7f1f.zip
cpython-2076d4f97ef514bb4dc4ca768fbaa3f538ce7f1f.tar.gz
cpython-2076d4f97ef514bb4dc4ca768fbaa3f538ce7f1f.tar.bz2
bpo-39474: Fix AST pos for expressions like (a)(b), (a)[b] and (a).b. (GH-18477)
(cherry picked from commit 6e619c48b8e804ece9521453fc8da0640a04d5b1) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_ast.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index e843d53..3e8a39d 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1642,6 +1642,33 @@ class EndPositionTests(unittest.TestCase):
self._check_content(s, call, s)
self._check_content(s, call.args[0], 'x. y .z')
+ def test_redundant_parenthesis(self):
+ s = '( ( ( a + b ) ) )'
+ v = ast.parse(s).body[0].value
+ self.assertEqual(type(v).__name__, 'BinOp')
+ self._check_content(s, v, 'a + b')
+ s2 = 'await ' + s
+ v = ast.parse(s2).body[0].value.value
+ self.assertEqual(type(v).__name__, 'BinOp')
+ self._check_content(s2, v, 'a + b')
+
+ def test_trailers_with_redundant_parenthesis(self):
+ tests = (
+ ('( ( ( a ) ) ) ( )', 'Call'),
+ ('( ( ( a ) ) ) ( b )', 'Call'),
+ ('( ( ( a ) ) ) [ b ]', 'Subscript'),
+ ('( ( ( a ) ) ) . b', 'Attribute'),
+ )
+ for s, t in tests:
+ with self.subTest(s):
+ v = ast.parse(s).body[0].value
+ self.assertEqual(type(v).__name__, t)
+ self._check_content(s, v, s)
+ s2 = 'await ' + s
+ v = ast.parse(s2).body[0].value.value
+ self.assertEqual(type(v).__name__, t)
+ self._check_content(s2, v, s)
+
def test_displays(self):
s1 = '[{}, {1, }, {1, 2,} ]'
s2 = '{a: b, f (): g () ,}'