FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.8] bpo-39579: Fix Attribute end_col_offset to point at the current… · python-emscripten/cpython@8b9cebc · GitHub

Repository navigation

Commit 8b9cebc

Browse files
authored
[3.8] bpo-39579: Fix Attribute end_col_offset to point at the current node (pythonGH-18405) (pythonGH-18408)
(cherry picked from commit d2e1098) https://bugs.python.org/issue39579 Automerge-Triggered-By: @gvanrossum
1 parent 97e00b3 commit 8b9cebc

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎Lib/test/test_ast.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def to_tuple(t):
140140
"@deco1\n@deco2()\n@deco3(1)\nclass C: pass",
141141
# Decorator with generator argument
142142
"@deco(a for a in b)\ndef f(): pass",
143+
# Decorator with attribute
144+
"@a.b.c\ndef f(): pass",
143145
# Simple assignment expression
144146
"(a := 1)",
145147
# Positional-only arguments
@@ -614,6 +616,11 @@ def test_issue18374_binop_col_offset(self):
614616
self.assertEqual(grandchild_binop.end_col_offset, 3)
615617
self.assertEqual(grandchild_binop.end_lineno, 1)
616618

619+
def test_issue39579_dotted_name_end_col_offset(self):
620+
tree = ast.parse('@a.b.c\ndef f(): pass')
621+
attr_b = tree.body[0].decorator_list[0].value
622+
self.assertEqual(attr_b.end_col_offset, 4)
623+
617624
class ASTHelpers_Test(unittest.TestCase):
618625
maxDiff = None
619626

@@ -1838,6 +1845,7 @@ def main():
18381845
('Module', [('AsyncFunctionDef', (4, 0), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (4, 15))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2', ('Load',)), [], []), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Constant', (3, 7), 1, None)], [])], None, None)], []),
18391846
('Module', [('ClassDef', (4, 0), 'C', [], [], [('Pass', (4, 9))], [('Name', (1, 1), 'deco1', ('Load',)), ('Call', (2, 1), ('Name', (2, 1), 'deco2', ('Load',)), [], []), ('Call', (3, 1), ('Name', (3, 1), 'deco3', ('Load',)), [('Constant', (3, 7), 1, None)], [])])], []),
18401847
('Module', [('FunctionDef', (2, 0), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (2, 9))], [('Call', (1, 1), ('Name', (1, 1), 'deco', ('Load',)), [('GeneratorExp', (1, 5), ('Name', (1, 6), 'a', ('Load',)), [('comprehension', ('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 17), 'b', ('Load',)), [], 0)])], [])], None, None)], []),
1848+
('Module', [('FunctionDef', (2, 0), 'f', ('arguments', [], [], None, [], [], None, []), [('Pass', (2, 9))], [('Attribute', (1, 1), ('Attribute', (1, 1), ('Name', (1, 1), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',))], None, None)], []),
18411849
('Module', [('Expr', (1, 0), ('NamedExpr', (1, 1), ('Name', (1, 1), 'a', ('Store',)), ('Constant', (1, 6), 1, None)))], []),
18421850
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', None, None)], [], None, [], [], None, []), [('Pass', (1, 14))], [], None, None)], []),
18431851
('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', None, None)], [('arg', (1, 12), 'c', None, None), ('arg', (1, 15), 'd', None, None), ('arg', (1, 18), 'e', None, None)], None, [], [], None, []), [('Pass', (1, 22))], [], None, None)], []),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change the ending column offset of `Attribute` nodes constructed in `ast_for_dotted_name` to point at the end of the current node and not at the end of the last `NAME` node.

‎Python/ast.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,11 +1715,12 @@ ast_for_dotted_name(struct compiling *c, const node *n)
17151715
return NULL;
17161716

17171717
for (i = 2; i < NCH(n); i+=2) {
1718-
id = NEW_IDENTIFIER(CHILD(n, i));
1718+
const node *child = CHILD(n, i);
1719+
id = NEW_IDENTIFIER(child);
17191720
if (!id)
17201721
return NULL;
17211722
e = Attribute(e, id, Load, lineno, col_offset,
1722-
n->n_end_lineno, n->n_end_col_offset, c->c_arena);
1723+
child->n_end_lineno, child->n_end_col_offset, c->c_arena);
17231724
if (!e)
17241725
return NULL;
17251726
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL