Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7845cf8

Browse files
committed
Make sure that atoms (Tuple, List, etc.) have lineno attributes
1 parent 4ba9001 commit 7845cf8

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Lib/compiler/transformer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self):
9999
def transform(self, tree):
100100
"""Transform an AST into a modified parse tree."""
101101
if type(tree) != type(()) and type(tree) != type([]):
102-
tree = parser.ast2tuple(tree,1)
102+
tree = parser.ast2tuple(tree, line_info=1)
103103
return self.compile_node(tree)
104104

105105
def parsesuite(self, text):
@@ -657,7 +657,9 @@ def power(self, nodelist):
657657
return node
658658

659659
def atom(self, nodelist):
660-
return self._atom_dispatch[nodelist[0][0]](nodelist)
660+
n = self._atom_dispatch[nodelist[0][0]](nodelist)
661+
n.lineno = nodelist[0][2]
662+
return n
661663

662664
def atom_lpar(self, nodelist):
663665
if nodelist[1][0] == token.RPAR:

Tools/compiler/compiler/transformer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self):
9999
def transform(self, tree):
100100
"""Transform an AST into a modified parse tree."""
101101
if type(tree) != type(()) and type(tree) != type([]):
102-
tree = parser.ast2tuple(tree,1)
102+
tree = parser.ast2tuple(tree, line_info=1)
103103
return self.compile_node(tree)
104104

105105
def parsesuite(self, text):
@@ -657,7 +657,9 @@ def power(self, nodelist):
657657
return node
658658

659659
def atom(self, nodelist):
660-
return self._atom_dispatch[nodelist[0][0]](nodelist)
660+
n = self._atom_dispatch[nodelist[0][0]](nodelist)
661+
n.lineno = nodelist[0][2]
662+
return n
661663

662664
def atom_lpar(self, nodelist):
663665
if nodelist[1][0] == token.RPAR:

0 commit comments

Comments
 (0)