mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
gh-99341: Cover type ignore nodes when incrementing line numbers (GH-99422)
This commit is contained in:
parent
bc3a11d21d
commit
1acdfec359
3 changed files with 20 additions and 0 deletions
|
|
@ -1036,6 +1036,18 @@ Module(
|
|||
self.assertEqual(ast.increment_lineno(src).lineno, 2)
|
||||
self.assertIsNone(ast.increment_lineno(src).end_lineno)
|
||||
|
||||
def test_increment_lineno_on_module(self):
|
||||
src = ast.parse(dedent("""\
|
||||
a = 1
|
||||
b = 2 # type: ignore
|
||||
c = 3
|
||||
d = 4 # type: ignore@tag
|
||||
"""), type_comments=True)
|
||||
ast.increment_lineno(src, n=5)
|
||||
self.assertEqual(src.type_ignores[0].lineno, 7)
|
||||
self.assertEqual(src.type_ignores[1].lineno, 9)
|
||||
self.assertEqual(src.type_ignores[1].tag, '@tag')
|
||||
|
||||
def test_iter_fields(self):
|
||||
node = ast.parse('foo()', mode='eval')
|
||||
d = dict(ast.iter_fields(node.body))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue