summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2011-11-04 21:29:24 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2011-11-04 21:29:24 (GMT)
commit9028a101440bd1526cf1fa0e77db8b4b1200fc29 (patch)
tree4434b3a5c747f20f9c0a78c15db3e5a1be0f514c
parent3dbb1f17cbbc6f616a75e902c527a41bb7fc8bfe (diff)
parent97c1bef6a4f3c522826386480c62ec27fe46301d (diff)
downloadcpython-9028a101440bd1526cf1fa0e77db8b4b1200fc29.zip
cpython-9028a101440bd1526cf1fa0e77db8b4b1200fc29.tar.gz
cpython-9028a101440bd1526cf1fa0e77db8b4b1200fc29.tar.bz2
Issue #13343: Fix a SystemError when a lambda expression uses a global
variable in the default value of a keyword-only argument: (lambda *, arg=GLOBAL_NAME: None)
-rw-r--r--Lib/test/test_keywordonlyarg.py8
-rw-r--r--Misc/NEWS4
-rw-r--r--Python/symtable.c3
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_keywordonlyarg.py b/Lib/test/test_keywordonlyarg.py
index 44be32c..61d40f9 100644
--- a/Lib/test/test_keywordonlyarg.py
+++ b/Lib/test/test_keywordonlyarg.py
@@ -162,6 +162,14 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
self.assertRaises(TypeError, Example.f, k1=1, k2=2)
+ def test_issue13343(self):
+ # The Python compiler must scan all symbols of a function to
+ # determine their scope: global, local, cell...
+ # This was not done for the default values of keyword
+ # arguments in a lambda definition, and the following line
+ # used to fail with a SystemError.
+ lambda *, k1=unittest: None
+
def test_main():
run_unittest(KeywordOnlyArgTestCase)
diff --git a/Misc/NEWS b/Misc/NEWS
index 358a6e3..5c1c4e5 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
+- Issue #13343: Fix a SystemError when a lambda expression uses a global
+ variable in the default value of a keyword-only argument:
+ (lambda *, arg=GLOBAL_NAME: None)
+
- Issue #12797: Added custom opener parameter to builtin open() and
FileIO.open().
diff --git a/Python/symtable.c b/Python/symtable.c
index 3578b0c..824a53f 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1300,6 +1300,9 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
return 0;
if (e->v.Lambda.args->defaults)
VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
+ if (e->v.Lambda.args->kw_defaults)
+ VISIT_KWONLYDEFAULTS(st,
+ e->v.Lambda.args->kw_defaults);
if (!symtable_enter_block(st, lambda,
FunctionBlock, (void *)e, e->lineno,
e->col_offset))