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.
Created on 2008年05月23日 19:09 by donmez, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg67261 - (view) | Author: Ismail Donmez (donmez) * | Date: 2008年05月23日 19:09 | |
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. |
|||
| msg67262 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2008年05月23日 19:21 | |
The behaviour is documented, e.g. in footnote 5.1 of http://docs.python.org/ref/lists.html It is fixed in Python 3. |
|||
| msg67263 - (view) | Author: Ismail Donmez (donmez) * | Date: 2008年05月23日 19:22 | |
But it only mentions python 2.3, time to update the footnote. |
|||
| msg67264 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2008年05月23日 19:33 | |
This is now fixed in r63569 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:34 | admin | set | github: 47201 |
| 2008年05月23日 19:33:47 | loewis | set | messages: + msg67264 |
| 2008年05月23日 19:23:00 | donmez | set | messages: + msg67263 |
| 2008年05月23日 19:21:32 | loewis | set | status: open -> closed resolution: fixed messages: + msg67262 nosy: + loewis |
| 2008年05月23日 19:09:45 | donmez | set | type: behavior components: + Interpreter Core, - Library (Lib) |
| 2008年05月23日 19:09:25 | donmez | create | |