[New-bugs-announce] [issue2952] List comprehensions are leaking variables
Ismail Donmez
report at bugs.python.org
Fri May 23 21:09:30 CEST 2008
New submission from Ismail Donmez <ismail at namtrac.org>:
Originally found at http://www.randombit.net/weblog/programming/variable_leak_in_list_compre
hensions.html
First example :
[~]> python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x=1
>>> [x for x in [1,2,3]]
[1, 2, 3]
>>> x
3
whoops x changed.
Another example from original post:
$ python
Python 2.4.4 (#1, Mar 7 2008, 14:54:19)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = { 1:2, 3:4 }
>>> nothere
Traceback (most recent call last):
File "", line 1, in ?
NameError: name 'nothere' is not defined
>>> [nothere for nothere in x.keys()]
[1, 3]
>>> nothere
3
This bug doesn't seem to affect py3k but it does python 2.4/2.5. Either
this should be fixed or documented as a caveat.
----------
components: Library (Lib)
messages: 67261
nosy: cartman
severity: normal
status: open
title: List comprehensions are leaking variables
versions: Python 2.5
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2952>
__________________________________
More information about the New-bugs-announce
mailing list