classification
Title: Nested lambdas in setattr() lose context in Python 2.7
Type: behavior Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Victor Liu, benjamin.peterson
Priority: normal Keywords:

Created on 2016-12-29 03:58 by Victor Liu, last changed 2016-12-29 04:25 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py Victor Liu, 2016-12-29 03:58
Messages (2)
msg284224 - (view) Author: Victor Liu (Victor Liu) Date: 2016-12-29 03:58
I would expect bug.py to output:
foo
bar
baz

but instead we observe:
baz
baz
baz

Replicated on Windows 10 Home Edition, Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)]
msg284228 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2016-12-29 04:25
https://docs.python.org/2/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
History
Date User Action Args
2016-12-29 04:25:25benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg284228

resolution: not a bug
2016-12-29 03:58:24Victor Liucreate