On 23 November 2017 at 14:36, Greg Ewing <greg.ewing@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@gmail.com   |   Brisbane, Australia