Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9028a10

Browse files
committed
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)
2 parents 3dbb1f1 + 97c1bef commit 9028a10

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_keywordonlyarg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ def f(self, *, k1=1, k2=2):
162162
self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
163163
self.assertRaises(TypeError, Example.f, k1=1, k2=2)
164164

165+
def test_issue13343(self):
166+
# The Python compiler must scan all symbols of a function to
167+
# determine their scope: global, local, cell...
168+
# This was not done for the default values of keyword
169+
# arguments in a lambda definition, and the following line
170+
# used to fail with a SystemError.
171+
lambda *, k1=unittest: None
172+
165173
def test_main():
166174
run_unittest(KeywordOnlyArgTestCase)
167175

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13343: Fix a SystemError when a lambda expression uses a global
14+
variable in the default value of a keyword-only argument:
15+
(lambda *, arg=GLOBAL_NAME: None)
16+
1317
- Issue #12797: Added custom opener parameter to builtin open() and
1418
FileIO.open().
1519

Python/symtable.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,9 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
13001300
return 0;
13011301
if (e->v.Lambda.args->defaults)
13021302
VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
1303+
if (e->v.Lambda.args->kw_defaults)
1304+
VISIT_KWONLYDEFAULTS(st,
1305+
e->v.Lambda.args->kw_defaults);
13031306
if (!symtable_enter_block(st, lambda,
13041307
FunctionBlock, (void *)e, e->lineno,
13051308
e->col_offset))

0 commit comments

Comments
 (0)