summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2019-12-12 21:40:21 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-12-12 21:40:21 (GMT)
commit025a602af7ee284d8db6955c26016f3f27d35536 (patch)
treef080f5fadbf276bc1dac0910c0ab9ecab81feeaa /Lib/test/test_ast.py
parent1988344a6bff253f017e053f69318ecf03587294 (diff)
downloadcpython-025a602af7ee284d8db6955c26016f3f27d35536.zip
cpython-025a602af7ee284d8db6955c26016f3f27d35536.tar.gz
cpython-025a602af7ee284d8db6955c26016f3f27d35536.tar.bz2
bpo-39031: Include elif keyword when producing lineno/col-offset info for if_stmt (GH-17582)
When parsing an "elif" node, lineno and col_offset of the node now point to the "elif" keyword and not to its condition, making it consistent with the "if" node. https://bugs.python.org/issue39031 Automerge-Triggered-By: @pablogsal
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index ca75a4a..955bc0d 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -68,6 +68,8 @@ exec_tests = [
"while v:pass",
# If
"if v:pass",
+ # If-Elif
+ "if a:\n pass\nelif b:\n pass",
# With
"with x as y: pass",
"with x as y, z as q: pass",
@@ -861,6 +863,12 @@ Module(
self.assertEqual(node.body[2].col_offset, 0)
self.assertEqual(node.body[2].lineno, 13)
+ def test_elif_stmt_start_position(self):
+ node = ast.parse('if a:\n pass\nelif b:\n pass\n')
+ elif_stmt = node.body[0].orelse[0]
+ self.assertEqual(elif_stmt.lineno, 3)
+ self.assertEqual(elif_stmt.col_offset, 0)
+
def test_literal_eval(self):
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
@@ -1843,6 +1851,7 @@ exec_results = [
('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [], None)], []),
('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])], []),
('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])], []),
+('Module', [('If', (1, 0), ('Name', (1, 3), 'a', ('Load',)), [('Pass', (2, 2))], [('If', (3, 0), ('Name', (3, 5), 'b', ('Load',)), [('Pass', (4, 2))], [])])], []),
('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('Name', (1, 10), 'y', ('Store',)))], [('Pass', (1, 13))], None)], []),
('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('Name', (1, 10), 'y', ('Store',))), ('withitem', ('Name', (1, 13), 'z', ('Load',)), ('Name', (1, 18), 'q', ('Store',)))], [('Pass', (1, 21))], None)], []),
('Module', [('Raise', (1, 0), ('Call', (1, 6), ('Name', (1, 6), 'Exception', ('Load',)), [('Constant', (1, 16), 'string', None)], []), None)], []),