[Python-checkins] r61067 - in python/trunk: Lib/compiler/ast.py Lib/compiler/transformer.py Lib/token.py Tools/compiler/ast.txt

facundo.batista python-checkins at python.org
Mon Feb 25 19:06:00 CET 2008


Author: facundo.batista
Date: Mon Feb 25 19:06:00 2008
New Revision: 61067
Modified:
 python/trunk/Lib/compiler/ast.py
 python/trunk/Lib/compiler/transformer.py
 python/trunk/Lib/token.py
 python/trunk/Tools/compiler/ast.txt
Log:
Issue 2117. Update compiler module to handle class decorators.
Thanks Thomas Herve
Modified: python/trunk/Lib/compiler/ast.py
==============================================================================
--- python/trunk/Lib/compiler/ast.py	(original)
+++ python/trunk/Lib/compiler/ast.py	Mon Feb 25 19:06:00 2008
@@ -308,11 +308,12 @@
 return "CallFunc(%s, %s, %s, %s)" % (repr(self.node), repr(self.args), repr(self.star_args), repr(self.dstar_args))
 
 class Class(Node):
- def __init__(self, name, bases, doc, code, lineno=None):
+ def __init__(self, name, bases, doc, code, decorators = None, lineno=None):
 self.name = name
 self.bases = bases
 self.doc = doc
 self.code = code
+ self.decorators = decorators
 self.lineno = lineno
 
 def getChildren(self):
@@ -321,16 +322,19 @@
 children.extend(flatten(self.bases))
 children.append(self.doc)
 children.append(self.code)
+ children.append(self.decorators)
 return tuple(children)
 
 def getChildNodes(self):
 nodelist = []
 nodelist.extend(flatten_nodes(self.bases))
 nodelist.append(self.code)
+ if self.decorators is not None:
+ nodelist.append(self.decorators)
 return tuple(nodelist)
 
 def __repr__(self):
- return "Class(%s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code))
+ return "Class(%s, %s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code), repr(self.decorators))
 
 class Compare(Node):
 def __init__(self, expr, ops, lineno=None):
Modified: python/trunk/Lib/compiler/transformer.py
==============================================================================
--- python/trunk/Lib/compiler/transformer.py	(original)
+++ python/trunk/Lib/compiler/transformer.py	Mon Feb 25 19:06:00 2008
@@ -232,6 +232,18 @@
 items.append(self.decorator(dec_nodelist[1:]))
 return Decorators(items)
 
+ def decorated(self, nodelist):
+ assert nodelist[0][0] == symbol.decorators
+ if nodelist[1][0] == symbol.funcdef:
+ n = [nodelist[0]] + list(nodelist[1][1:])
+ return self.funcdef(n)
+ elif nodelist[1][0] == symbol.classdef:
+ decorators = self.decorators(nodelist[0][1:])
+ cls = self.classdef(nodelist[1][1:])
+ cls.decorators = decorators
+ return cls
+ raise WalkerError()
+
 def funcdef(self, nodelist):
 # -6 -5 -4 -3 -2 -1
 # funcdef: [decorators] 'def' NAME parameters ':' suite
Modified: python/trunk/Lib/token.py
==============================================================================
--- python/trunk/Lib/token.py	(original)
+++ python/trunk/Lib/token.py	Mon Feb 25 19:06:00 2008
@@ -71,6 +71,7 @@
 for _name, _value in globals().items():
 if type(_value) is type(0):
 tok_name[_value] = _name
+del _name, _value
 
 
 def ISTERMINAL(x):
Modified: python/trunk/Tools/compiler/ast.txt
==============================================================================
--- python/trunk/Tools/compiler/ast.txt	(original)
+++ python/trunk/Tools/compiler/ast.txt	Mon Feb 25 19:06:00 2008
@@ -14,7 +14,7 @@
 Decorators: nodes!
 Function: decorators&, name*, argnames*, defaults!, flags*, doc*, code
 Lambda: argnames*, defaults!, flags*, code
-Class: name*, bases!, doc*, code
+Class: name*, bases!, doc*, code, decorators& = None
 Pass: 
 Break: 
 Continue: 
@@ -97,7 +97,7 @@
 self.kwargs = 1
 
 init(GenExpr):
- self.argnames = ['[outmost-iterable]']
+ self.argnames = ['.0']
 self.varargs = self.kwargs = None
 
 init(GenExprFor):


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /