From 97c1bef6a4f3c522826386480c62ec27fe46301d Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Fri, 4 Nov 2011 22:17:45 +0100 Subject: 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) --- Lib/test/test_keywordonlyarg.py | 8 ++++++++ Misc/NEWS | 4 ++++ Python/symtable.c | 3 +++ 3 files changed, 15 insertions(+) diff --git a/Lib/test/test_keywordonlyarg.py b/Lib/test/test_keywordonlyarg.py index d7f7541..3aebd68 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 7ef1977..e8917ed 100644 --- 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. diff --git a/Python/symtable.c b/Python/symtable.c index 5eff364..1ec51f7 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -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)) -- cgit v0.12