[Python-Dev] Tricky way of of creating a generator via a comprehension expression
Nick Coghlan
ncoghlan at gmail.com
Wed Nov 22 23:54:49 EST 2017
On 23 November 2017 at 14:36, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:
> Paul Moore wrote:
>
>> 3. List comprehensions are the same as list(the equivalent generator
>> expression).
>>
>
> I don't think that's ever been quite true -- there have
> always been odd cases such as what happens if you
> raise StopIteration in list(generator_expression).
>
> To my mind, these equivalences have never been intended
> as exact descriptions of the semantics, but just a way
> of quickly getting across the general idea. Further
> words are needed to pin down all the fine details.
>
Getting the name resolution to be identical was definitely one of my goals
when working on the Python 3 comprehension scoping changes.
The fact that implicit scopes and yield expressions interact strangely was
just a pre-existing oddity from when PEP 342 was first implemented (and one
we were able to avoid for async/await by retaining the same "await is only
permitted in async comprehensions" constraint that exists for explicit
scopes).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171123/762166b9/attachment.html>
More information about the Python-Dev
mailing list