mirror of https://github.com/python/cpython
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)
This commit is contained in:
commit
9028a10144
|
@ -162,6 +162,14 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
|
||||||
self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
|
self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
|
||||||
self.assertRaises(TypeError, Example.f, k1=1, k2=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():
|
def test_main():
|
||||||
run_unittest(KeywordOnlyArgTestCase)
|
run_unittest(KeywordOnlyArgTestCase)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
|
||||||
Core and Builtins
|
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
|
- Issue #12797: Added custom opener parameter to builtin open() and
|
||||||
FileIO.open().
|
FileIO.open().
|
||||||
|
|
||||||
|
|
|
@ -1300,6 +1300,9 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
|
||||||
return 0;
|
return 0;
|
||||||
if (e->v.Lambda.args->defaults)
|
if (e->v.Lambda.args->defaults)
|
||||||
VISIT_SEQ(st, expr, 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,
|
if (!symtable_enter_block(st, lambda,
|
||||||
FunctionBlock, (void *)e, e->lineno,
|
FunctionBlock, (void *)e, e->lineno,
|
||||||
e->col_offset))
|
e->col_offset))
|
||||||
|
|
Loading…
Reference in New Issue