| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 97e00b3 commit 8b9cebc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,6 +140,8 @@ def to_tuple(t): | |||
| 140 | 140 | "@deco1\n@deco2()\n@deco3(1)\nclass C: pass", | |
| 141 | 141 | # Decorator with generator argument | |
| 142 | 142 | "@deco(a for a in b)\ndef f(): pass", | |
| 143 | + # Decorator with attribute | ||
| 144 | + "@a.b.c\ndef f(): pass", | ||
| 143 | 145 | # Simple assignment expression | |
| 144 | 146 | "(a := 1)", | |
| 145 | 147 | # Positional-only arguments | |
@@ -614,6 +616,11 @@ def test_issue18374_binop_col_offset(self): | |||
| 614 | 616 | self.assertEqual(grandchild_binop.end_col_offset, 3) | |
| 615 | 617 | self.assertEqual(grandchild_binop.end_lineno, 1) | |
| 616 | 618 | ||
| 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 | + | ||
| 617 | 624 | class ASTHelpers_Test(unittest.TestCase): | |
| 618 | 625 | maxDiff = None | |
| 619 | 626 | ||
@@ -1838,6 +1845,7 @@ def main(): | |||
| 1838 | 1845 | ('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)], []), | |
| 1839 | 1846 | ('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)], [])])], []), | |
| 1840 | 1847 | ('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)], []), | ||
| 1841 | 1849 | ('Module', [('Expr', (1, 0), ('NamedExpr', (1, 1), ('Name', (1, 1), 'a', ('Store',)), ('Constant', (1, 6), 1, None)))], []), | |
| 1842 | 1850 | ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', (1, 6), 'a', None, None)], [], None, [], [], None, []), [('Pass', (1, 14))], [], None, None)], []), | |
| 1843 | 1851 | ('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)], []), | |
| Original file line number | Diff line number | Diff 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. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1715,11 +1715,12 @@ ast_for_dotted_name(struct compiling *c, const node *n) | |||
| 1715 | 1715 | return NULL; | |
| 1716 | 1716 | ||
| 1717 | 1717 | 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); | ||
| 1719 | 1720 | if (!id) | |
| 1720 | 1721 | return NULL; | |
| 1721 | 1722 | 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); | ||
| 1723 | 1724 | if (!e) | |
| 1724 | 1725 | return NULL; | |
| 1725 | 1726 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments