mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-42316: Allow unparenthesized walrus operator in indexes (GH-23317)
This commit is contained in:
parent
cb3e5ed071
commit
cae60187cf
4 changed files with 29 additions and 7 deletions
|
@ -10639,7 +10639,7 @@ slices_rule(Parser *p)
|
|||
return _res;
|
||||
}
|
||||
|
||||
// slice: expression? ':' expression? [':' expression?] | expression
|
||||
// slice: expression? ':' expression? [':' expression?] | named_expression
|
||||
static expr_ty
|
||||
slice_rule(Parser *p)
|
||||
{
|
||||
|
@ -10701,18 +10701,18 @@ slice_rule(Parser *p)
|
|||
D(fprintf(stderr, "%*c%s slice[%d-%d]: %s failed!\n", p->level, ' ',
|
||||
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression? ':' expression? [':' expression?]"));
|
||||
}
|
||||
{ // expression
|
||||
{ // named_expression
|
||||
if (p->error_indicator) {
|
||||
D(p->level--);
|
||||
return NULL;
|
||||
}
|
||||
D(fprintf(stderr, "%*c> slice[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "expression"));
|
||||
D(fprintf(stderr, "%*c> slice[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "named_expression"));
|
||||
expr_ty a;
|
||||
if (
|
||||
(a = expression_rule(p)) // expression
|
||||
(a = named_expression_rule(p)) // named_expression
|
||||
)
|
||||
{
|
||||
D(fprintf(stderr, "%*c+ slice[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression"));
|
||||
D(fprintf(stderr, "%*c+ slice[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "named_expression"));
|
||||
_res = a;
|
||||
if (_res == NULL && PyErr_Occurred()) {
|
||||
p->error_indicator = 1;
|
||||
|
@ -10723,7 +10723,7 @@ slice_rule(Parser *p)
|
|||
}
|
||||
p->mark = _mark;
|
||||
D(fprintf(stderr, "%*c%s slice[%d-%d]: %s failed!\n", p->level, ' ',
|
||||
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "expression"));
|
||||
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "named_expression"));
|
||||
}
|
||||
_res = NULL;
|
||||
done:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue