[Python-checkins] cpython (merge 3.2 -> default): Issue #13343: Fix a SystemError when a lambda expression uses a global

amaury.forgeotdarc python-checkins at python.org
Fri Nov 4 22:29:49 CET 2011


http://hg.python.org/cpython/rev/bddb455439d0
changeset: 73367:bddb455439d0
parent: 73365:ca78ed7393bf
parent: 73366:1e0e821d2626
user: Amaury Forgeot d'Arc <amauryfa at gmail.com>
date: Fri Nov 04 22:29:24 2011 +0100
summary:
 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)
files:
 Lib/test/test_keywordonlyarg.py | 8 ++++++++
 Misc/NEWS | 4 ++++
 Python/symtable.c | 3 +++
 3 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_keywordonlyarg.py b/Lib/test/test_keywordonlyarg.py
--- a/Lib/test/test_keywordonlyarg.py
+++ b/Lib/test/test_keywordonlyarg.py
@@ -162,6 +162,14 @@
 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 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
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1300,6 +1300,9 @@
 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))
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /