mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
e26aa24b47
commit
85dbd2d767
3 changed files with 20 additions and 0 deletions
|
@ -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 (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue