]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #13343: Fix a SystemError when a lambda expression uses a global
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 4 Nov 2011 21:17:45 +0000 (22:17 +0100)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 4 Nov 2011 21:17:45 +0000 (22:17 +0100)
variable in the default value of a keyword-only argument:
(lambda *, arg=GLOBAL_NAME: None)

Lib/test/test_keywordonlyarg.py
Misc/NEWS
Python/symtable.c

index d7f7541837d7018101a97c00edfdbdbbf08482b9..3aebd68b2a17f22ef2ca413074abab94b390dfc0 100644 (file)
@@ -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)
 
index 7ef197731728308a8ffd2d056dde12a3d937cd92..e8917ed3bc498193c973bb2c0a938acb11d23ef0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.2.3?
 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 #10519: Avoid unnecessary recursive function calls in
   setobject.c.
 
index 5eff364439dfdf7ad3f1421e88152416ef3ee32c..1ec51f708c358831d1d23343763edd08ea993ee2 100644 (file)
@@ -1334,6 +1334,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))