A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2014-November/137060.html below:

Change StopIteration handling inside generators

[Python-Dev] PEP 479: Change StopIteration handling inside generatorsChris Angelico rosuav at gmail.com
Sun Nov 23 02:06:18 CET 2014
On Sun, Nov 23, 2014 at 11:51 AM, Ron Adam <ron3200 at gmail.com> wrote:
>
>
> On 11/22/2014 06:20 PM, Chris Angelico wrote:
>>
>> Hmmm, there's no such thing as tuple comprehensions.
>
> Just didn't think it through quite well enough.  But you are correct, that
> would be a generator expression.
>
> One less case to worry about. :-)

Ah right, no probs.

>>> >And it would be changed to this...
>>> >
>>> >     def comp_expression():
>>> >         for x in itr:          # StopIteration caught here.
>>> >             if cond:
>>> >                list.append(expr)
>>> >
>>> >     # StopIteration from cond and expr caught here.
>>> >     lst = list(x for x in comp_expression())
>
> Right, the list.append() should be a yield(expr).

In that case, your second generator expression is entirely redundant;
all you want is list(comp_expression()). But the example doesn't say
*why* this version should terminate on a StopIteration raised by expr,
when the statement form would print an exception traceback.

> The real question is how much breakage would such a change make?  That will
> probably need a patch in order to test it out.

There's one attached here:

http://bugs.python.org/issue22906

It doesn't create a __future__ directive, just applies the change globally.

ChrisA
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4