[Python-checkins] python/dist/src/Lib/compiler pycodegen.py, 1.71,
1.72 transformer.py, 1.42, 1.43
mwh at users.sourceforge.net
mwh at users.sourceforge.net
Tue Aug 17 19:29:37 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib/compiler
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1056/Lib/compiler
Modified Files:
pycodegen.py transformer.py
Log Message:
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)
Index: pycodegen.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/compiler/pycodegen.py,v
retrieving revision 1.71
retrieving revision 1.72
diff -C2 -d -r1.71 -r1.72
*** pycodegen.py 7 Aug 2004 19:21:56 -0000 1.71
--- pycodegen.py 17 Aug 2004 17:29:14 -0000 1.72
***************
*** 368,377 ****
def _visitFuncOrLambda(self, node, isLambda=0):
if not isLambda and node.decorators:
! for decorator in reversed(node.decorators.nodes):
self.visit(decorator)
ndecorators = len(node.decorators.nodes)
else:
ndecorators = 0
!
gen = self.FunctionGen(node, self.scopes, isLambda,
self.class_name, self.get_module())
--- 368,377 ----
def _visitFuncOrLambda(self, node, isLambda=0):
if not isLambda and node.decorators:
! for decorator in node.decorators.nodes:
self.visit(decorator)
ndecorators = len(node.decorators.nodes)
else:
ndecorators = 0
!
gen = self.FunctionGen(node, self.scopes, isLambda,
self.class_name, self.get_module())
Index: transformer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/compiler/transformer.py,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** transformer.py 4 Aug 2004 02:36:18 -0000 1.42
--- transformer.py 17 Aug 2004 17:29:14 -0000 1.43
***************
*** 202,212 ****
def decorator(self, nodelist):
# '@' dotted_name [ '(' [arglist] ')' ]
! assert len(nodelist) in (2, 4, 5)
assert nodelist[0][0] == token.AT
assert nodelist[1][0] == symbol.dotted_name
funcname = self.decorator_name(nodelist[1][1:])
! if len(nodelist) > 2:
assert nodelist[2][0] == token.LPAR
expr = self.com_call_function(funcname, nodelist[3])
--- 202,213 ----
def decorator(self, nodelist):
# '@' dotted_name [ '(' [arglist] ')' ]
! assert len(nodelist) in (3, 5, 6)
assert nodelist[0][0] == token.AT
+ assert nodelist[-1][0] == token.NEWLINE
assert nodelist[1][0] == symbol.dotted_name
funcname = self.decorator_name(nodelist[1][1:])
! if len(nodelist) > 3:
assert nodelist[2][0] == token.LPAR
expr = self.com_call_function(funcname, nodelist[3])
***************
*** 218,231 ****
def decorators(self, nodelist):
# decorators: decorator ([NEWLINE] decorator)* NEWLINE
- listlen = len(nodelist)
- i = 0
items = []
! while i < listlen:
! assert nodelist[i][0] == symbol.decorator
! items.append(self.decorator(nodelist[i][1:]))
! i += 1
!
! if i < listlen and nodelist[i][0] == token.NEWLINE:
! i += 1
return Decorators(items)
--- 219,226 ----
def decorators(self, nodelist):
# decorators: decorator ([NEWLINE] decorator)* NEWLINE
items = []
! for dec_nodelist in nodelist:
! assert dec_nodelist[0] == symbol.decorator
! items.append(self.decorator(dec_nodelist[1:]))
return Decorators(items)
More information about the Python-checkins
mailing list