Issue1110705
Created on 2005-01-27 13:27 by sdahlbac, last changed 2008-02-22 00:51 by stutzbach. This issue is now closed.
| Messages (8) | |||
|---|---|---|---|
| msg24070 - (view) | Author: Simon Dahlbacka (sdahlbac) | Date: 2005-01-27 13:27 | |
The variable used for iteration in list comprehensions is still in scope after the list comprehension. >>>foo = [1, 2, 3] >>>bar = [dummy + 1 for dummy in foo] >>>dummy 3 Expected result: NameError: name 'dummy' is not defined |
|||
| msg24071 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2005-01-27 13:48 | |
Logged In: YES user_id=80475 This is not a bug. It is behaving as designed. The thought was to emulate the behavior of an equivalent for-loop. In future versions of Python, Guido would like to change the design to hide the induction variable. So, someday, you'll get your wish. |
|||
| msg24072 - (view) | Author: Simon Dahlbacka (sdahlbac) | Date: 2005-01-27 14:11 | |
Logged In: YES user_id=750513 Seemingly (according to: http://docs.python.org/ref/lists.html) this is indeed a bug that should be fixed. |
|||
| msg24073 - (view) | Author: Josiah Carlson (josiahcarlson) | Date: 2005-01-29 19:54 | |
Logged In: YES user_id=341410 "this behavior is deprecated, and relying on it will not work once this bug is fixed in a future release" As we have not yet reached the future release in which this will happen, and the 'bug' is both known and documented, it will be 'fixed' when it is fixed. The reason that it has not yet been 'fixed' is because there is a nontrivial amount of code that would break if it was. I personally would call it a deprecated 'feature'. Then again, I use it more often than I should. |
|||
| msg24074 - (view) | Author: Christoph Zwerschke (cito) | Date: 2006-04-30 11:52 | |
Logged In: YES user_id=193957 Either this is a bug that should be fixed, or the documentation that says it is a bug should be fixed (http://www.python.org/doc/current/ref/lists.html#foot4519). That fact that an ordinary for loop leaks the control variables into the containing scope may be a design feature, but the same behavior for list comprehensions can hardly be called a design feature. At least not one that is reasonable. I would rather call it a bug. It definitely contradicts the principle of least surprise. |
|||
| msg62667 - (view) | Author: Daniel Stutzbach (stutzbach) ![]() |
Date: 2008-02-22 00:39 | |
The resolution on this bug reads, "In future versions of Python, Guido would like to change the design to hide the induction variable. So, someday, you'll get your wish." Can this bug be re-opened and the wart removed in 3.0? |
|||
| msg62669 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2008-02-22 00:47 | |
It's already been implemented for Py3.0. |
|||
| msg62670 - (view) | Author: Daniel Stutzbach (stutzbach) ![]() |
Date: 2008-02-22 00:51 | |
Wonderful! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-02-22 00:51:39 | stutzbach | set | messages: + msg62670 |
| 2008-02-22 00:47:23 | rhettinger | set | messages: + msg62669 |
| 2008-02-22 00:39:21 | stutzbach | set | nosy:
+ stutzbach messages: + msg62667 |
| 2005-01-27 13:27:22 | sdahlbac | create | |
