[pypy-commit] pypy py3k: CPython issue 13343: Fix a crash when a lambda expression uses a global
amauryfa
noreply at buildbot.pypy.org
Wed Oct 24 23:35:21 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r58409:9ccaaa9b4bac
Date: 2012-10-24 23:04 +0200
http://bitbucket.org/pypy/pypy/changeset/9ccaaa9b4bac/
Log: CPython issue 13343: Fix a crash when a lambda expression uses a
global variable in the default value of a keyword-only argument:
(lambda *, arg=GLOBAL_NAME: None)
diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -2477,6 +2477,12 @@
for node in seq:
node.walkabout(self)
+ def visit_kwonlydefaults(self, seq):
+ if seq is not None:
+ for node in seq:
+ if node:
+ node.walkabout(self)
+
def default_visitor(self, node):
raise NodeVisitorNotImplemented
diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -356,10 +356,7 @@
args = func.args
assert isinstance(args, ast.arguments)
self.visit_sequence(args.defaults)
- if args.kw_defaults:
- for arg in args.kw_defaults:
- if arg:
- arg.walkabout(self)
+ self.visit_kwonlydefaults(args.kw_defaults)
self._visit_annotations(func)
self.visit_sequence(func.decorator_list)
new_scope = FunctionScope(func.name, func.lineno, func.col_offset)
@@ -453,6 +450,7 @@
args = lamb.args
assert isinstance(args, ast.arguments)
self.visit_sequence(args.defaults)
+ self.visit_kwonlydefaults(args.kw_defaults)
new_scope = FunctionScope("lambda", lamb.lineno, lamb.col_offset)
self.push_scope(new_scope, lamb)
lamb.args.walkabout(self)
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -376,3 +376,7 @@
scp = self.mod_scope("with x as y: pass")
assert scp.lookup("_[1]") == symtable.SCOPE_LOCAL
assert scp.lookup("_[2]") == symtable.SCOPE_LOCAL
+
+ def test_issue13343(self):
+ scp = self.mod_scope("lambda *, k1=x, k2: None")
+ assert scp.lookup("x") == symtable.SCOPE_GLOBAL_IMPLICIT
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -222,6 +222,12 @@
self.emit("for node in seq:", 3)
self.emit("node.walkabout(self)", 4)
self.emit("")
+ self.emit("def visit_kwonlydefaults(self, seq):", 1)
+ self.emit("if seq is not None:", 2)
+ self.emit("for node in seq:", 3)
+ self.emit("if node:", 4)
+ self.emit("node.walkabout(self)", 5)
+ self.emit("")
self.emit("def default_visitor(self, node):", 1)
self.emit("raise NodeVisitorNotImplemented", 2)
self.emit("")
More information about the pypy-commit
mailing list