summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-03-03 22:25:44 (GMT)
committerGitHub <noreply@github.com>2020-03-03 22:25:44 (GMT)
commitbe501ca2419a91546dea85ef4f36945545458589 (patch)
tree75288eb978f78b97d2da5b2a052b9908531066f3 /Python/ast.c
parent116fd4af7370706d0d99ac7c70541ef965672d4e (diff)
downloadcpython-be501ca2419a91546dea85ef4f36945545458589.zip
cpython-be501ca2419a91546dea85ef4f36945545458589.tar.gz
cpython-be501ca2419a91546dea85ef4f36945545458589.tar.bz2
bpo-39702: Relax grammar restrictions on decorators (PEP 614) (GH-18570)
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c72
1 files changed, 4 insertions, 68 deletions
diff --git a/Python/ast.c b/Python/ast.c
index ad25565..0aed54c 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1692,79 +1692,15 @@ ast_for_arguments(struct compiling *c, const node *n)
}
static expr_ty
-ast_for_dotted_name(struct compiling *c, const node *n)
-{
- expr_ty e;
- identifier id;
- int lineno, col_offset;
- int i;
- node *ch;
-
- REQ(n, dotted_name);
-
- lineno = LINENO(n);
- col_offset = n->n_col_offset;
-
- ch = CHILD(n, 0);
- id = NEW_IDENTIFIER(ch);
- if (!id)
- return NULL;
- e = Name(id, Load, lineno, col_offset,
- ch->n_end_lineno, ch->n_end_col_offset, c->c_arena);
- if (!e)
- return NULL;
-
- for (i = 2; i < NCH(n); i+=2) {
- const node *child = CHILD(n, i);
- id = NEW_IDENTIFIER(child);
- if (!id)
- return NULL;
- e = Attribute(e, id, Load, lineno, col_offset,
- child->n_end_lineno, child->n_end_col_offset, c->c_arena);
- if (!e)
- return NULL;
- }
-
- return e;
-}
-
-static expr_ty
ast_for_decorator(struct compiling *c, const node *n)
{
- /* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */
- expr_ty d = NULL;
- expr_ty name_expr;
+ /* decorator: '@' namedexpr_test NEWLINE */
REQ(n, decorator);
REQ(CHILD(n, 0), AT);
- REQ(RCHILD(n, -1), NEWLINE);
-
- name_expr = ast_for_dotted_name(c, CHILD(n, 1));
- if (!name_expr)
- return NULL;
-
- if (NCH(n) == 3) { /* No arguments */
- d = name_expr;
- name_expr = NULL;
- }
- else if (NCH(n) == 5) { /* Call with no arguments */
- d = Call(name_expr, NULL, NULL,
- name_expr->lineno, name_expr->col_offset,
- CHILD(n, 3)->n_end_lineno, CHILD(n, 3)->n_end_col_offset,
- c->c_arena);
- if (!d)
- return NULL;
- name_expr = NULL;
- }
- else {
- d = ast_for_call(c, CHILD(n, 3), name_expr,
- CHILD(n, 1), CHILD(n, 2), CHILD(n, 4));
- if (!d)
- return NULL;
- name_expr = NULL;
- }
-
- return d;
+ REQ(CHILD(n, 2), NEWLINE);
+
+ return ast_for_expr(c, CHILD(n, 1));
}
static asdl_seq*