diff options
author | Guido van Rossum <guido@python.org> | 2006-10-27 23:31:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-10-27 23:31:49 (GMT) |
commit | 4f72a78684bbfcdc43ceeabb240ceee54706c4b0 (patch) | |
tree | 743c27c5125dcef580cffe77395fe97bedf40d5f /Lib/compiler/pycodegen.py | |
parent | fc2a0a8e3cb1d40fd965576060c28c8bd2ea1ad5 (diff) | |
download | cpython-4f72a78684bbfcdc43ceeabb240ceee54706c4b0.zip cpython-4f72a78684bbfcdc43ceeabb240ceee54706c4b0.tar.gz cpython-4f72a78684bbfcdc43ceeabb240ceee54706c4b0.tar.bz2 |
Jiwon Seo's PEP 3102 implementation.
See SF#1549670.
The compiler package has not yet been updated.
Diffstat (limited to 'Lib/compiler/pycodegen.py')
-rw-r--r-- | Lib/compiler/pycodegen.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index 83d0481..b08a307 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -378,6 +378,12 @@ class CodeGenerator: walk(node.code, gen) gen.finish() self.set_lineno(node) + for keyword in node.kwonlyargs: + default = keyword.expr + if isinstance(default, ast.EmptyNode): + continue + self.emit('LOAD_CONST', keyword.name) + self.visit(default) for default in node.defaults: self.visit(default) self._makeClosure(gen, len(node.defaults)) @@ -1320,7 +1326,9 @@ class AbstractFunctionCode: name = func.name args, hasTupleArg = generateArgList(func.argnames) + kwonlyargs = generateKwonlyArgList(func.kwonlyargs) self.graph = pyassem.PyFlowGraph(name, func.filename, args, + kwonlyargs=kwonlyargs, optimized=1) self.isLambda = isLambda self.super_init() @@ -1456,6 +1464,13 @@ def generateArgList(arglist): raise ValueError, "unexpect argument type:", elt return args + extra, count +def generateKwonlyArgList(keywordOnlyArgs): + kwonlyargs = {} + for elt in keywordOnlyArgs: + assert isinstance(elt, ast.Keyword) + kwonlyargs[elt.name] = elt.expr + return kwonlyargs + def findOp(node): """Find the op (DELETE, LOAD, STORE) in an AssTuple tree""" v = OpFinder() |