Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ kwds[arg_ty]:
| '**' a=plain_name { a }
annotation[expr_ty]: expression

decorators[asdl_seq*]: a=('@' f=factor NEWLINE { f })+ { a }
decorators[asdl_seq*]: a=('@' f=named_expression NEWLINE { f })+ { a }

class_def[stmt_ty]:
| a=decorators b=class_def_raw { class_def_decorators(p, a, b) }
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_peg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ def f():
async def d():
pass
'''),
('decorator_with_expression',
'''
@lambda x: 42
def f():
pass
'''),
('decorator_with_expression_and_walrus',
'''
@x:=lambda x: 42
def f():
pass
'''),
('del_attribute', 'del a.b'),
('del_call_attribute', 'del a().c'),
('del_call_genexp_attribute', 'del a(i for i in b).c'),
Expand Down
14 changes: 7 additions & 7 deletions Parser/pegen/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3612,15 +3612,15 @@ annotation_rule(Parser *p)
return res;
}

// decorators: (('@' factor NEWLINE))+
// decorators: (('@' named_expression NEWLINE))+
static asdl_seq*
decorators_rule(Parser *p)
{
asdl_seq* res = NULL;
if (is_memoized(p, decorators_type, &res))
return res;
int mark = p->mark;
{ // (('@' factor NEWLINE))+
{ // (('@' named_expression NEWLINE))+
asdl_seq * a;
if (
(a = _loop1_61_rule(p))
Expand Down Expand Up @@ -11122,7 +11122,7 @@ _tmp_60_rule(Parser *p)
return res;
}

// _loop1_61: ('@' factor NEWLINE)
// _loop1_61: ('@' named_expression NEWLINE)
static asdl_seq *
_loop1_61_rule(Parser *p)
{
Expand All @@ -11137,7 +11137,7 @@ _loop1_61_rule(Parser *p)
}
ssize_t children_capacity = 1;
ssize_t n = 0;
{ // ('@' factor NEWLINE)
{ // ('@' named_expression NEWLINE)
void *_tmp_116_var;
while (
(_tmp_116_var = _tmp_116_rule(p))
Expand Down Expand Up @@ -13254,22 +13254,22 @@ _tmp_115_rule(Parser *p)
return res;
}

// _tmp_116: '@' factor NEWLINE
// _tmp_116: '@' named_expression NEWLINE
static void *
_tmp_116_rule(Parser *p)
{
void * res = NULL;
if (is_memoized(p, _tmp_116_type, &res))
return res;
int mark = p->mark;
{ // '@' factor NEWLINE
{ // '@' named_expression NEWLINE
expr_ty f;
void *literal;
void *newline_var;
if (
(literal = expect_token(p, 49))
&&
(f = factor_rule(p))
(f = named_expression_rule(p))
&&
(newline_var = newline_token(p))
)
Expand Down