This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 2022-04-11 14:58 by admin. 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
2022-04-11 14:58:41adminsetgithub: 73287
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