gh-99341: Cover type ignore nodes when incrementing line numbers (GH-99422)

(cherry picked from commit 1acdfec359)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-11-22 03:03:26 -08:00 committed by GitHub
parent e26aa24b47
commit 85dbd2d767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -236,6 +236,12 @@ def increment_lineno(node, n=1):
location in a file.
"""
for child in walk(node):
# TypeIgnore is a special case where lineno is not an attribute
# but rather a field of the node itself.
if isinstance(child, TypeIgnore):
child.lineno = getattr(child, 'lineno', 0) + n
continue
if 'lineno' in child._attributes:
child.lineno = getattr(child, 'lineno', 0) + n
if (