classification
Title: Lambda keyword-only argument not updating co_freevars
Type: crash Stage: needs patch
Components: Interpreter Core Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Joshua.Landau, amaury.forgeotdarc, eric.araujo, mark.dickinson, python-dev
Priority: critical Keywords: patch

Created on 2011-11-04 19:37 by Joshua.Landau, last changed 2011-11-18 14:52 by eric.araujo. This issue is now closed.

Files
File name Uploaded Description Edit
issue13343.patch amaury.forgeotdarc, 2011-11-04 20:45 review
Messages (8)
msg147026 - (view) Author: Joshua Landau (Joshua.Landau) * Date: 2011-11-04 19:37
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.
msg147031 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-11-04 20:42
Here is a patch, with a minimal test.
msg147033 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-11-04 20:45
same patch, without tabs.
msg147037 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-11-04 20:59
Patch looks good to me.
msg147043 - (view) Author: Roundup Robot (python-dev) Date: 2011-11-04 21:29
New changeset 1e0e821d2626 by Amaury Forgeot d'Arc in branch '3.2':
Issue #13343: Fix a SystemError when a lambda expression uses a global
http://hg.python.org/cpython/rev/1e0e821d2626

New changeset bddb455439d0 by Amaury Forgeot d'Arc in branch 'default':
Issue #13343: Fix a SystemError when a lambda expression uses a global
http://hg.python.org/cpython/rev/bddb455439d0
msg147044 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-11-04 21:32
It was a bug in Python compiler, thanks for the report!
msg147046 - (view) Author: Joshua Landau (Joshua.Landau) * Date: 2011-11-04 21:36
Glad to help :)
It's made my day. I get to boast at school now!
msg147877 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-11-18 14:52
> It's made my day. I get to boast at school now!
You could do more of that if you got a patch committed!  See http://docs.python.org/devguide and http://mail.python.org/mailman/listinfo/core-mentorship for more info if you’re interested.
History
Date User Action Args
2011-11-18 14:52:20eric.araujosetnosy: + eric.araujo
messages: + msg147877
2011-11-04 21:36:13Joshua.Landausetmessages: + msg147046
2011-11-04 21:32:07amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg147044
2011-11-04 21:29:56python-devsetnosy: + python-dev
messages: + msg147043
2011-11-04 20:59:40mark.dickinsonsetnosy: + mark.dickinson
messages: + msg147037
2011-11-04 20:45:19amaury.forgeotdarcsetfiles: - issue13343.patch
2011-11-04 20:45:06amaury.forgeotdarcsetfiles: + issue13343.patch

messages: + msg147033
2011-11-04 20:42:41amaury.forgeotdarcsetfiles: + issue13343.patch

nosy: + amaury.forgeotdarc
messages: + msg147031

keywords: + patch
2011-11-04 20:29:08mark.dickinsonsetpriority: normal -> critical
stage: needs patch
versions: + Python 3.3
2011-11-04 19:37:32Joshua.Landaucreate