New submission from Joshua Landau <joshua.landau...@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.

EXAMPLE:
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 <rep...@bugs.python.org>
<http://bugs.python.org/issue13343>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to