mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-40726: handle uninitalized end_lineno on ast.increment_lineno (GH-20312)
(cherry picked from commit 8f4380d2f5
)
Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
This commit is contained in:
parent
ea680631b4
commit
a1320989f5
3 changed files with 23 additions and 3 deletions
|
@ -812,6 +812,12 @@ Module(
|
|||
'lineno=1, col_offset=4, end_lineno=1, end_col_offset=5), lineno=1, '
|
||||
'col_offset=0, end_lineno=1, end_col_offset=5))'
|
||||
)
|
||||
src = ast.Call(col_offset=1, lineno=1, end_lineno=1, end_col_offset=1)
|
||||
new = ast.copy_location(src, ast.Call(col_offset=None, lineno=None))
|
||||
self.assertIsNone(new.end_lineno)
|
||||
self.assertIsNone(new.end_col_offset)
|
||||
self.assertEqual(new.lineno, 1)
|
||||
self.assertEqual(new.col_offset, 1)
|
||||
|
||||
def test_fix_missing_locations(self):
|
||||
src = ast.parse('write("spam")')
|
||||
|
@ -851,6 +857,11 @@ Module(
|
|||
'lineno=4, col_offset=4, end_lineno=4, end_col_offset=5), lineno=4, '
|
||||
'col_offset=0, end_lineno=4, end_col_offset=5))'
|
||||
)
|
||||
src = ast.Call(
|
||||
func=ast.Name("test", ast.Load()), args=[], keywords=[], lineno=1
|
||||
)
|
||||
self.assertEqual(ast.increment_lineno(src).lineno, 2)
|
||||
self.assertIsNone(ast.increment_lineno(src).end_lineno)
|
||||
|
||||
def test_iter_fields(self):
|
||||
node = ast.parse('foo()', mode='eval')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue