mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
This is Mark Russell's patch:
[ 1009560 ] Fix @decorator evaluation order From the description: Changes in this patch: - Change Grammar/Grammar to require newlines between adjacent decorators. - Fix order of evaluation of decorators in the C (compile.c) and python (Lib/compiler/pycodegen.py) compilers - Add better order of evaluation check to test_decorators.py (test_eval_order) - Update the decorator documentation in the reference manual (improve description of evaluation order and update syntax description) and the comment: Used Brett's evaluation order (see http://mail.python.org/pipermail/python-dev/2004-August/047835.html) (I'm checking this in for Anthony who was having problems getting SF to talk to him)
This commit is contained in:
parent
b51b23405b
commit
0ccff074cd
8 changed files with 142 additions and 96 deletions
|
@ -2364,7 +2364,7 @@ validate_testlist_gexp(node *tree)
|
|||
}
|
||||
|
||||
/* decorator:
|
||||
* '@' dotted_name [ '(' [arglist] ')' ]
|
||||
* '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
|
||||
*/
|
||||
static int
|
||||
validate_decorator(node *tree)
|
||||
|
@ -2372,41 +2372,37 @@ validate_decorator(node *tree)
|
|||
int ok;
|
||||
int nch = NCH(tree);
|
||||
ok = (validate_ntype(tree, decorator) &&
|
||||
(nch == 2 || nch == 4 || nch == 5) &&
|
||||
(nch == 3 || nch == 5 || nch == 6) &&
|
||||
validate_at(CHILD(tree, 0)) &&
|
||||
validate_dotted_name(CHILD(tree, 1)));
|
||||
validate_dotted_name(CHILD(tree, 1)) &&
|
||||
validate_newline(RCHILD(tree, -1)));
|
||||
|
||||
if (ok && nch != 2) {
|
||||
ok = (validate_lparen(CHILD(tree, 2)) &&
|
||||
validate_rparen(RCHILD(tree, -1)));
|
||||
if (ok && nch != 3) {
|
||||
ok = (validate_lparen(CHILD(tree, 2)) &&
|
||||
validate_rparen(RCHILD(tree, -2)));
|
||||
|
||||
if (ok && nch == 5)
|
||||
ok = validate_arglist(CHILD(tree, 3));
|
||||
if (ok && nch == 6)
|
||||
ok = validate_arglist(CHILD(tree, 3));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
/* decorators:
|
||||
* decorator ([NEWLINE] decorator)* NEWLINE
|
||||
* decorator+
|
||||
*/
|
||||
static int
|
||||
validate_decorators(node *tree)
|
||||
{
|
||||
int i, nch, ok;
|
||||
nch = NCH(tree);
|
||||
ok = validate_ntype(tree, decorators) && nch >= 2;
|
||||
ok = validate_ntype(tree, decorators) && nch >= 1;
|
||||
|
||||
i = 0;
|
||||
while (ok && i < nch - 1) {
|
||||
for (i = 0; ok && i < nch; ++i)
|
||||
ok = validate_decorator(CHILD(tree, i));
|
||||
if (TYPE(CHILD(tree, i + 1)) == NEWLINE)
|
||||
++i;
|
||||
++i;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
/* funcdef:
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue