mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally" Implementation by Mark Russell, from SF #979728.
This commit is contained in:
parent
fd7dc5169c
commit
c2a5a63654
28 changed files with 2965 additions and 2335 deletions
|
@ -366,6 +366,13 @@ class CodeGenerator:
|
|||
self._visitFuncOrLambda(node, isLambda=1)
|
||||
|
||||
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())
|
||||
walk(node.code, gen)
|
||||
|
@ -382,6 +389,9 @@ class CodeGenerator:
|
|||
else:
|
||||
self.emit('LOAD_CONST', gen)
|
||||
self.emit('MAKE_FUNCTION', len(node.defaults))
|
||||
|
||||
for i in range(ndecorators):
|
||||
self.emit('CALL_FUNCTION', 1)
|
||||
|
||||
def visitClass(self, node):
|
||||
gen = self.ClassGen(node, self.scopes,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue