diff options
author | Michael W. Hudson <mwh@python.net> | 2004-08-17 17:29:16 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2004-08-17 17:29:16 (GMT) |
commit | 0ccff074cd806bc7e963a1e0ff6ce25e0d11cce9 (patch) | |
tree | c8e7be65d3051aa878fe53169b9bdeb4d3b4227e /Modules/parsermodule.c | |
parent | b51b23405b6cf82ab4ec20f3d5ef4b895bd0786f (diff) | |
download | cpython-0ccff074cd806bc7e963a1e0ff6ce25e0d11cce9.zip cpython-0ccff074cd806bc7e963a1e0ff6ce25e0d11cce9.tar.gz cpython-0ccff074cd806bc7e963a1e0ff6ce25e0d11cce9.tar.bz2 |
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)
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 81d96e1..5f53982 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -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: * |