Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95372 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2015-08-14 08:37 +0200 |
| Last post | 2015-08-14 08:37 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Ensure unwanted names removed in class definition Peter Otten <__peter__@web.de> - 2015-08-14 08:37 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-08-14 08:37 +0200 |
| Subject | Re: Ensure unwanted names removed in class definition |
| Message-ID | <mailman.6.1439534270.4764.python-list@python.org> |
Ben Finney wrote:
> Peter Otten <__peter__@web.de> writes:
>
>> Ben Finney wrote:
>>
>> > Peter Otten <__peter__@web.de> writes:
>> >
>> > That's an unexpected inconsistency between list comprehensions
>> > versus generator expressions, then. Is that documented explicitly in
>> > the Python 2 documentation?
>>
>> https://docs.python.org/2.4/whatsnew/node4.html
>
> Or
> <URL:https://docs.python.org/2/whatsnew/2.4.html#pep-289-generator-expressions>.
>
> Also in the PEP that introduces generator expressions, PEP 289:
>
> List comprehensions also "leak" their loop variable into the
> surrounding scope. This will also change in Python 3.0, so that the
> semantic definition of a list comprehension in Python 3.0 will be
> equivalent to list(<generator expression>).
>
> <URL:https://www.python.org/dev/peps/pep-0289/#the-details>
>
> Thanks for seeking the answer. Can you describe an improvement to
> <URL:https://docs.python.org/2/reference/expressions.html#list-displays>
> that makes clear this unexpected, deprecated behaviour which is only in
> Python 2?
>
A sentence like that in the PEP would help, but I think the main problem is
that list comprehensions and lists are subsumed under list displays.
>From a user perspective
[f(x) for x in y]
has more in common with {x: f(x) for x in y} than with [x, y, z].
I think it would be great if list comprehensions could be moved in a
separate paragraph or into
5.2.5 Displays for [lists,] sets and dictionaries
with a note
For backwards compatibility list comprehensions leak their loop variables
into the surrounding scope. Set and dictionary displays do not leak.
I don't know if such a modification is feasible; I'm definitely no "language
lawyer".
Back to top | Article view | comp.lang.python
csiph-web