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

This commit is contained in:
Batuhan Taskaya 2022-11-22 13:41:14 +03:00 committed by GitHub
parent bc3a11d21d
commit 1acdfec359
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -237,6 +237,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 (