[New-bugs-announce] [issue13343] Lambda keyword-only argument not updating co_freevars

Joshua Landau report at bugs.python.org
Fri Nov 4 20:37:32 CET 2011

New submission from Joshua Landau <joshua.landau.ws at gmail.com>:

When setting defaults to keyword-only arguments in lambdas which are inside non-global scopes, cPython doesn't push the name to it's closure's co_freevars.

global_variable = None
(lambda: (lambda *, keyword_only=global_variable: None))()

Because the inner lambda hasn't told the outer lambda to put global_variable in co_freevars, it fails to create the default to keyword_only. This only happens if the inner function is a lambda and you are setting a keyword_only variable.

It does not cause a crash if global_variable is local to the outer lambda, as the opcode LOAD_FAST is still created properly (as opposed to LOAD_NAME).

It does not crash if global_variable is used elsewhere in the outer function as co_freevars will be updated with it, allowing LOAD_NAME to retrieve it.

I've never done a bug here before and I'm unsure what to say, so please be nice and correct me if I'm doing it wrong.

components: Interpreter Core
messages: 147026
nosy: Joshua.Landau
priority: normal
severity: normal
status: open
title: Lambda keyword-only argument not updating co_freevars
type: crash
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list