diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-02-12 20:37:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 20:37:49 (GMT) |
commit | 6e619c48b8e804ece9521453fc8da0640a04d5b1 (patch) | |
tree | b0814052868c0397aa1cae70827bf331d7e27be4 /Lib/test | |
parent | 674935b8caf33e47c78f1b8e197b1b77a04992d2 (diff) | |
download | cpython-6e619c48b8e804ece9521453fc8da0640a04d5b1.zip cpython-6e619c48b8e804ece9521453fc8da0640a04d5b1.tar.gz cpython-6e619c48b8e804ece9521453fc8da0640a04d5b1.tar.bz2 |
bpo-39474: Fix AST pos for expressions like (a)(b), (a)[b] and (a).b. (GH-18477)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ast.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 6d1e419..2ed4657 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -1707,6 +1707,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 () ,}' |