Re: [Python-Dev] PEP 479 (Change StopIteration handling inside generators) -- hopefully final text

2014-12-05 Thread Nick Coghlan
On 6 December 2014 at 04:42, Guido van Rossum wrote: > For those who haven't followed along, here's the final text of PEP 479, with > a brief Acceptance section added. The basic plan hasn't changed, but there's > a lot more clarifying text and discussion of a few counter-proposals. Please > send s

[Python-Dev] PEP 479 (Change StopIteration handling inside generators) -- hopefully final text

2014-12-05 Thread Guido van Rossum
For those who haven't followed along, here's the final text of PEP 479, with a brief Acceptance section added. The basic plan hasn't changed, but there's a lot more clarifying text and discussion of a few counter-proposals. Please send suggestions for editorial improvements to p...@python.org. The

Re: [Python-Dev] PEP 479

2014-11-30 Thread Nick Coghlan
On 30 November 2014 at 12:31, Chris Angelico wrote: > On Sun, Nov 30, 2014 at 1:04 PM, Jim J. Jewett wrote: >> (4) It can happen because of "yield from" yielding from an iterator, >> rather than a generator? > > No; as I understand it (though maybe I'm wrong too), "yield from" will > yield every

Re: [Python-Dev] PEP 479

2014-11-29 Thread Chris Angelico
On Sun, Nov 30, 2014 at 1:04 PM, Jim J. Jewett wrote: > I have a strong suspicion that I'm missing something; I have been > persuaded both directions too often to believe I have a grip on the > real issue. > > So I'm putting out some assumptions; please tell me if I'm wrong, and > maybe make them

[Python-Dev] PEP 479

2014-11-29 Thread Jim J. Jewett
I have a strong suspicion that I'm missing something; I have been persuaded both directions too often to believe I have a grip on the real issue. So I'm putting out some assumptions; please tell me if I'm wrong, and maybe make them more explicit in the PEP. (1) The change will only affect situat

Re: [Python-Dev] PEP 479 and asyncio

2014-11-29 Thread Guido van Rossum
On Sat, Nov 29, 2014 at 9:07 AM, Nick Coghlan wrote: > Guido wrote a specific micro-benchmark for that case in one of the > other threads. On his particular system, the overhead was around 150 > ns per link in the chain at the point the data processing pipeline was > shut down. In most scenarios

Re: [Python-Dev] PEP 479 and asyncio

2014-11-29 Thread Nick Coghlan
On 30 November 2014 at 02:45, Olemis Lang wrote: > On 11/28/14, Guido van Rossum wrote: > [...] >> >> @Olemis: You never showed examples of how your code would be used, so it's >> hard to understand what you're trying to do and how PEP 479 affects you. >> > > The intention is not to restart the d

Re: [Python-Dev] PEP 479 and asyncio

2014-11-29 Thread Olemis Lang
On 11/28/14, Guido van Rossum wrote: [...] > > @Olemis: You never showed examples of how your code would be used, so it's > hard to understand what you're trying to do and how PEP 479 affects you. > The intention is not to restart the debate . PEP is approved , it's done ... but ... as a side-e

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Guido van Rossum
@Victor: I'm glad you found a work-around. Maybe you can let your users control it with a flag? It is often true that straddling code pays a performance cost. Hopefully the slight performance dip might be an incentive for people to start thinking about porting to asyncio. @Olemis: You never showed

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Olemis Lang
correction ... On 11/28/14, Olemis Lang wrote: > > try: >... > except RuntimeError: >return > ... should be {{{#!py # inside generator function body try: ... except StopIteration: return }}} [...] -- Regards, Olemis - @olemislc Apache(tm) Bloodhound contributor http://issue

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Olemis Lang
off-topic , not about asyncio but related to the PEP and other things been discussed in this thread On 11/28/14, Victor Stinner wrote: > 2014-11-28 3:49 GMT+01:00 Nick Coghlan : > [...] > > So yes, it may help to have a new specialized exception, even if "it > works" with RuntimeError. > This is

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Victor Stinner
2014-11-28 3:49 GMT+01:00 Nick Coghlan : > I think between contextlib and Trollius, the case is starting to be > made for raising an UnhandledStopIteration subclass of RuntimeError, > rather than a generic RuntimeError. I modified Trollius to test such idea: * Return inherits from Exception (not

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Chris Angelico
On Fri, Nov 28, 2014 at 8:18 PM, Victor Stinner wrote: > 2014-11-28 10:12 GMT+01:00 Greg Ewing : >> I don't understand. If I'm interpreting PEP 479 correctly, in >> 'x = yield from foo', a StopIteration raised by foo.__next__() >> doesn't get turned into a RuntimeError > > The Trollius coroutine u

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Victor Stinner
2014-11-28 10:12 GMT+01:00 Greg Ewing : > I don't understand. If I'm interpreting PEP 479 correctly, in > 'x = yield from foo', a StopIteration raised by foo.__next__() > doesn't get turned into a RuntimeError The Trollius coroutine uses "raise Return(value)" which is basically a "raise StopIterat

Re: [Python-Dev] PEP 479 and asyncio

2014-11-28 Thread Greg Ewing
Guido van Rossum wrote: The issue here is that asyncio only interprets StopIteration as returning from the generator (with a possible value), while a Trollius coroutine must use "raise Return()" to specify a return value; this works as long as Return is a subclass of StopIteration, but PEP 479

Re: [Python-Dev] PEP 479 and asyncio

2014-11-27 Thread Nick Coghlan
On 28 November 2014 at 08:09, Victor Stinner wrote: > 2014-11-27 22:54 GMT+01:00 Victor Stinner : >> I don't see how it would work. > > If it cannot be fixed, would it make sense to allow trollius to > continue to work as it currently works with something like "from > __past__ import generator_don

Re: [Python-Dev] PEP 479 and asyncio

2014-11-27 Thread Chris Angelico
On Fri, Nov 28, 2014 at 8:54 AM, Victor Stinner wrote: > def return_value(value): > if 0: > yield > raise Return(value) This is one known significant backward-incompatibility issue with this PEP - it'll be difficult to make this work on Python 2.7, where "return value" would be a

Re: [Python-Dev] PEP 479 and asyncio

2014-11-27 Thread Victor Stinner
2014-11-27 22:54 GMT+01:00 Victor Stinner : > I don't see how it would work. If it cannot be fixed, would it make sense to allow trollius to continue to work as it currently works with something like "from __past__ import generator_dont_stop"? When I talked with a friend about the transition from

Re: [Python-Dev] PEP 479 and asyncio

2014-11-27 Thread Victor Stinner
2014-11-27 20:06 GMT+01:00 Guido van Rossum : > The issue here is that asyncio only interprets StopIteration as returning > from the generator (with a possible value), I'm not sure that the issue is directly related to asyncio. trollius_coro() raises a StopIteration to return the result to caller

Re: [Python-Dev] PEP 479 and asyncio

2014-11-27 Thread Guido van Rossum
On Thu, Nov 27, 2014 at 10:08 AM, Victor Stinner wrote: > I'm trying to follow the discussion about the PEP 479 (Change > StopIteration handling inside generators), but it's hard to read all > messages. I'm concerned by trollius and asyncio which heavily rely on > StopIteration. > > Trollius curr

[Python-Dev] PEP 479 and asyncio

2014-11-27 Thread Victor Stinner
Hi, I'm trying to follow the discussion about the PEP 479 (Change StopIteration handling inside generators), but it's hard to read all messages. I'm concerned by trollius and asyncio which heavily rely on StopIteration. Trollius currently supports running asyncio coroutines: a trollius coroutine

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-27 Thread Nick Coghlan
On 27 November 2014 at 09:50, Guido van Rossum wrote: > On Wed, Nov 26, 2014 at 3:15 PM, Nick Coghlan wrote: >> This is actually the second iteration of this bug: the original >> implementation *always* suppressed StopIteration. PJE caught that one before >> Python 2.5 was released, but we didn't

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Chris Angelico
On Thu, Nov 27, 2014 at 8:57 AM, Isaac Schwabacher wrote: >> Can you summarize that in a self-contained form for inclusion in the PEP? >> >> (That was a rhetorical question. :-) > > Sure. Is it on GitHub? ;D Thanks Isaac, I've incorporated your edits. https://raw.githubusercontent.com/Rosuav/Gen

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Isaac Schwabacher
> Can you summarize that in a self-contained form for inclusion in the PEP? > > (That was a rhetorical question. :-) Sure. Is it on GitHub? ;D ijs ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Uns

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Guido van Rossum
On Wed, Nov 26, 2014 at 3:15 PM, Nick Coghlan wrote: > > On 27 Nov 2014 03:58, "Paul Moore" wrote: > > > > On 26 November 2014 at 17:19, Guido van Rossum wrote: > > > It's hard to use as an example because the behavior of contextlib is an > > > integral part of it -- currently for me the exampl

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Guido van Rossum
You can use the README here: https://github.com/Rosuav/GenStopIter On Wed, Nov 26, 2014 at 1:57 PM, Isaac Schwabacher wrote: > > Can you summarize that in a self-contained form for inclusion in the PEP? > > > > (That was a rhetorical question. :-) > > Sure. Is it on GitHub? ;D > > ijs > -- -

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Nick Coghlan
On 27 Nov 2014 03:58, "Paul Moore" wrote: > > On 26 November 2014 at 17:19, Guido van Rossum wrote: > > It's hard to use as an example because the behavior of contextlib is an > > integral part of it -- currently for me the example boils down to "there is > > a bug in contextlib" > > Hmm, fair po

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Isaac Schwabacher
On 14-11-26, Guido van Rossum wrote: > On Wed, Nov 26, 2014 at 8:54 AM, Paul Moore wrote: > > > On 26 November 2014 at 16:24, Isaac Schwabacher wrote: > > > This actually leads to a good example of why the PEP is necessary: > > [...] > > > > Oh! If that's the current behaviour, then it probably

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Guido van Rossum
Can you summarize that in a self-contained form for inclusion in the PEP? (That was a rhetorical question. :-) On Wed, Nov 26, 2014 at 12:17 PM, Isaac Schwabacher wrote: > On 14-11-26, Guido van Rossum wrote: > > On Wed, Nov 26, 2014 at 8:54 AM, Paul Moore wrote: > > > > > On 26 November 2014

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Ethan Furman
On 11/26/2014 08:54 AM, Paul Moore wrote: > On 26 November 2014 at 16:24, Isaac Schwabacher wrote: >> This actually leads to a good example of why the PEP is necessary: > [...] > > Oh! If that's the current behaviour, then it probably needs to go into > the PEP as a motivating example. It's far m

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Paul Moore
On 26 November 2014 at 17:19, Guido van Rossum wrote: > It's hard to use as an example because the behavior of contextlib is an > integral part of it -- currently for me the example boils down to "there is > a bug in contextlib" Hmm, fair point. I was assuming that the bug in contextlib can't be

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Guido van Rossum
On Wed, Nov 26, 2014 at 8:54 AM, Paul Moore wrote: > On 26 November 2014 at 16:24, Isaac Schwabacher > wrote: > > This actually leads to a good example of why the PEP is necessary: > [...] > > Oh! If that's the current behaviour, then it probably needs to go into > the PEP as a motivating exampl

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Paul Moore
On 26 November 2014 at 16:24, Isaac Schwabacher wrote: > This actually leads to a good example of why the PEP is necessary: [...] Oh! If that's the current behaviour, then it probably needs to go into the PEP as a motivating example. It's far more convincing than most of the other arguments I've

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Isaac Schwabacher
On 11/26/14, Nick Coghlan wrote: > On 26 November 2014 at 04:04, Guido van Rossum wrote: > > On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico wrote: > >> > >> On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher > >> wrote: > >> > Yield can also raise StopIteration, if it's thrown in. The current

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-26 Thread Isaac Schwabacher
On 11/26/14, Nick Coghlan wrote: > On 26 November 2014 at 04:04, Guido van Rossum wrote: > > On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico wrote: > >> > >> On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher > >> wrote: > >> > Yield can also raise StopIteration, if it's thrown in. The current

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Nick Coghlan
On 26 November 2014 at 04:04, Guido van Rossum wrote: > On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico wrote: >> >> On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher >> wrote: >> > Yield can also raise StopIteration, if it's thrown in. The current >> > interaction of generator.throw(StopIterat

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Isaac Schwabacher
On 11/25/14, Chris Angelico wrote: > On Wed, Nov 26, 2014 at 2:20 AM, Steven D'Aprano wrote: > > I wouldn't interpret it like that. > > > > Calling next() on an empty iterator raises StopIteration. That's not a > > bug indicating a failure, it's the protocol working as expected. Your > > response

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Guido van Rossum
On Tue, Nov 25, 2014 at 10:12 AM, Isaac Schwabacher wrote: > On 11/25/14, Guido van Rossum wrote: > > On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico ros...@gmail.com')" target="1">ros...@gmail.com> wrote: > > > > > On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher > > > ischwabac...@wisc.edu

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Isaac Schwabacher
On 11/25/14, Guido van Rossum wrote: > On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico ros...@gmail.com> wrote: > > > On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher > > > 't=ischwabac...@wisc.edu>> wrote: > > > Yield can also raise StopIteration, if its thrown in. The current > > > interac

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Guido van Rossum
On Tue, Nov 25, 2014 at 9:49 AM, Chris Angelico wrote: > On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher > wrote: > > Yield can also raise StopIteration, if it's thrown in. The current > interaction of generator.throw(StopIteration) with yield from can't be > emulated under the PEP's behavior

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Chris Angelico
On Wed, Nov 26, 2014 at 4:45 AM, Isaac Schwabacher wrote: > Yield can also raise StopIteration, if it's thrown in. The current > interaction of generator.throw(StopIteration) with yield from can't be > emulated under the PEP's behavior, though it's not clear that that's a > problem. > Hrm. I h

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Chris Angelico
On Wed, Nov 26, 2014 at 2:20 AM, Steven D'Aprano wrote: > I wouldn't interpret it like that. > > Calling next() on an empty iterator raises StopIteration. That's not a > bug indicating a failure, it's the protocol working as expected. Your > response to that may be to catch the StopIteration and i

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-25 Thread Steven D'Aprano
On Mon, Nov 24, 2014 at 10:22:54AM +1100, Chris Angelico wrote: > My point is that doing the same errant operation on a list or a dict > will give different exceptions. In the same way, calling next() on an > empty iterator will raise StopIteration normally, but might raise > RuntimeError instead.

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-24 Thread Guido van Rossum
On Mon, Nov 24, 2014 at 4:21 PM, Alexander Belopolsky < alexander.belopol...@gmail.com> wrote: > > On Wed, Nov 19, 2014 at 3:10 PM, Guido van Rossum > wrote: > >> There's a new PEP proposing to change how to treat StopIteration bubbling >> up out of a generator frame (not caused by a return from

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-24 Thread Alexander Belopolsky
On Wed, Nov 19, 2014 at 3:10 PM, Guido van Rossum wrote: > There's a new PEP proposing to change how to treat StopIteration bubbling > up out of a generator frame (not caused by a return from the frame). The > proposal is to replace such a StopIteration with a RuntimeError (chained to > the origi

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Steven D'Aprano
On Sun, Nov 23, 2014 at 08:17:00AM -0800, Ethan Furman wrote: > While I am in favor of PEP 479, and I have to agree with Raymond that > this isn't pretty. > > Currently, next() accepts an argument of what to return if the > iterator is empty. Can we enhance that in some way so that the > over

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Chris Angelico
On Mon, Nov 24, 2014 at 10:18 AM, Ron Adam wrote: >> The stop hack won't work in either (currently it does work in >> genexps), but you'd get a different exception type if you attempt it. >> This is correct. It's broadly similar to this distinction: >> > >>>{1:2,3:4}[50] >> >> Traceback (most

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Ron Adam
On 11/23/2014 04:15 PM, Chris Angelico wrote: On Mon, Nov 24, 2014 at 5:28 AM, Ron Adam wrote: >With the passage of the PEP, it will change what is different about them >once it's in full effect. The stop hack won't work in both, and you may get >a RuntimeError in generator expressions where

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Chris Angelico
On Mon, Nov 24, 2014 at 5:28 AM, Ron Adam wrote: > With the passage of the PEP, it will change what is different about them > once it's in full effect. The stop hack won't work in both, and you may get > a RuntimeError in generator expressions where you would get StopIteration in > list-comps. (

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Ron Adam
On 11/23/2014 04:08 AM, Terry Reedy wrote: On 11/22/2014 5:23 PM, Chris Angelico wrote: On Sun, Nov 23, 2014 at 8:03 AM, Ron Adam wrote: Making comprehensions work more like generator expressions would, IMO, imply making the same change to all for loops: having a StopIteration raised by the

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Ethan Furman
On 11/22/2014 12:30 PM, Raymond Hettinger wrote: Pre-PEP 479: --- > def middleware_generator(source_generator): > it = source_generator() > input_value = next(it) > output_value = do_something_interesting(input_value) > yield output_value Post-PEP 479:

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Paul Moore
On 23 November 2014 at 15:25, Chris Angelico wrote: > Thank you, it's nice to have a successful one to counterbalance the > "failure" of PEP 463. (Which, incidentally, never actually got a > resolution. It's still showing up as 'Draft' status.) I think it's worth pointing out that both this and P

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Chris Angelico
On Mon, Nov 24, 2014 at 2:11 AM, Ethan Furman wrote: > On 11/22/2014 08:53 PM, Guido van Rossum wrote: >> >> In order to save everyone's breath, I am *accepting* the proposal of PEP >> 479. > > Excellent. > > Chris, thank you for your time, effort, and thoroughness in championing this > PEP. > T

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Ethan Furman
On 11/22/2014 08:53 PM, Guido van Rossum wrote: > > In order to save everyone's breath, I am *accepting* the proposal of PEP > 479. Excellent. Chris, thank you for your time, effort, and thoroughness in championing this PEP. -- ~Ethan~ signature.asc Description: OpenPGP digital signature ___

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-23 Thread Terry Reedy
On 11/22/2014 5:23 PM, Chris Angelico wrote: On Sun, Nov 23, 2014 at 8:03 AM, Ron Adam wrote: Making comprehensions work more like generator expressions would, IMO, imply making the same change to all for loops: having a StopIteration raised by the body of the loop quietly terminate the loop.

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Guido van Rossum
In order to save everyone's breath, I am *accepting* the proposal of PEP 479. The transition plan is: - "from __future__ import generator_stop" in 3.5, and a silent deprecation if StopIteration is allowed to bubble out of a generator (i.e. no warning is printed unless you explicitly turn it on) -

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ron Adam
On 11/22/2014 07:06 PM, Chris Angelico wrote: On Sun, Nov 23, 2014 at 11:51 AM, Ron Adam 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 b

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ethan Furman
On 11/22/2014 05:11 PM, Raymond Hettinger wrote: >> On Nov 22, 2014, at 2:45 PM, Chris Angelico wrote: >> >> Does your middleware_generator work with just a single element, >> yielding either one output value or none? > > I apologize if I didn't make the point clearly. The middleware example was

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Chris Angelico
On Sun, Nov 23, 2014 at 12:11 PM, Raymond Hettinger wrote: > The worry is that your proposal intentionally breaks that code which is > currently > bug free, clean, fast, stable, and relying on a part of the API that has > been > guaranteed and documented from day one. (I'd just like to mention th

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Raymond Hettinger
> On Nov 22, 2014, at 2:45 PM, Chris Angelico wrote: > > Does your middleware_generator work with just a single element, > yielding either one output value or none? I apologize if I didn't make the point clearly. The middleware example was just simple outline of calling next(), doing some pr

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Chris Angelico
On Sun, Nov 23, 2014 at 11:51 AM, Ron Adam 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 wo

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ron Adam
On 11/22/2014 06:20 PM, Chris Angelico wrote: On Sun, Nov 23, 2014 at 11:05 AM, Ron Adam wrote: >Se we have these... > > Tuple Comprehension (...) > List Comprehension [...] > Dict Comprehension {...} Colon make's it different from sets. > Set Comprehension {...} > >I

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Chris Angelico
On Sun, Nov 23, 2014 at 11:05 AM, Ron Adam wrote: > Se we have these... > > Tuple Comprehension (...) > List Comprehension [...] > Dict Comprehension {...} Colon make's it different from sets. > Set Comprehension {...} > > I don't think there is any other way to create the

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ron Adam
On 11/22/2014 04:23 PM, Chris Angelico wrote: On Sun, Nov 23, 2014 at 8:03 AM, Ron Adam wrote: >>Making comprehensions work more like generator expressions >>would, IMO, imply making the same change to all for loops: having a >>StopIteration raised by the body of the loop quietly terminate th

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Chris Angelico
On Sun, Nov 23, 2014 at 7:30 AM, Raymond Hettinger wrote: > Legitimate Use Cases for Raising StopIteration in a Generator > > > In a producer/consumer generator chain, the input generator signals > it is done by raising StopIteration and

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Chris Angelico
On Sun, Nov 23, 2014 at 8:03 AM, Ron Adam wrote: >> Making comprehensions work more like generator expressions >> would, IMO, imply making the same change to all for loops: having a >> StopIteration raised by the body of the loop quietly terminate the >> loop. > > > I'm not suggesting making any c

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ron Adam
On 11/22/2014 03:01 PM, Terry Reedy wrote: Then both a comprehension and a generator expressions can be viewed as defining iterators, A comprehension is not an iterator. The above would make a list or set comprehension the same as feeding a genexp to list() or set(). Correct, but we coul

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ron Adam
On 11/22/2014 02:16 PM, Chris Angelico wrote: On Sun, Nov 23, 2014 at 6:49 AM, Ron Adam wrote: > >OPTION 1: > >Make comprehensions act more like generator expressions. > >It would mean a while loop in the object creation point is converted to a >for loop. (or something equivalent.) > >Then bo

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Terry Reedy
On 11/22/2014 2:49 PM, Ron Adam wrote: On 11/22/2014 08:31 AM, Nick Coghlan wrote: I'm definitely coming around to the point of view that, even if we wouldn't design it the way it currently works given a blank slate, the alternative design doesn't provide sufficient benefit to justify the cos

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Raymond Hettinger
> On Nov 22, 2014, at 6:31 AM, Nick Coghlan wrote: > > I'm definitely coming around to the point of view that, even if we wouldn't > design it the way it currently works given a blank slate, the alternative > design doesn't provide sufficient benefit to justify the cost of changing the > beha

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Chris Angelico
On Sun, Nov 23, 2014 at 6:49 AM, Ron Adam wrote: > > OPTION 1: > > Make comprehensions act more like generator expressions. > > It would mean a while loop in the object creation point is converted to a > for loop. (or something equivalent.) > > Then both a comprehension and a generator expressions

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ethan Furman
On 11/22/2014 06:31 AM, Nick Coghlan wrote: > > A particularly relevant variant of the idiom is the approach of writing > "__iter__" directly as a generator, rather than creating a separate custom > iterator class. In that context, the similarities between the __iter__ > implementation and the cor

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Ron Adam
On 11/22/2014 08:31 AM, Nick Coghlan wrote: On 22 Nov 2014 02:51, "Antoine Pitrou" mailto:solip...@pitrou.net>> wrote: > > On Fri, 21 Nov 2014 05:47:58 -0800 > Raymond Hettinger mailto:raymond.hettin...@gmail.com>> wrote: > > > > Another issue is that it breaks the way I and others have t

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-22 Thread Nick Coghlan
On 22 Nov 2014 02:51, "Antoine Pitrou" wrote: > > On Fri, 21 Nov 2014 05:47:58 -0800 > Raymond Hettinger wrote: > > > > Another issue is that it breaks the way I and others have taught for years that generators are a kind of iterator (an object implementing the iterator protocol) and that a prima

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Guido van Rossum
On Fri, Nov 21, 2014 at 9:18 AM, Steven D'Aprano wrote: > I fear that there is one specific corner case that will be impossible to > deal with in a backwards-compatible way supporting both Python 2 and 3 > in one code base: the use of `return value` in a generator. > > In Python 2.x through 3.1,

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Guido van Rossum
On Fri, Nov 21, 2014 at 8:47 AM, Antoine Pitrou wrote: > On Fri, 21 Nov 2014 05:47:58 -0800 > Raymond Hettinger wrote: > > > > Another issue is that it breaks the way I and others have taught for > years that generators are a kind of iterator (an object implementing the > iterator protocol) and

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Steven D'Aprano
On Thu, Nov 20, 2014 at 11:36:54AM -0800, Guido van Rossum wrote: [...] > That said, I think for most people the change won't matter, some people > will have to apply one of a few simple fixes, and a rare few will have to > rewrite their code in a non-trivial way (sometimes this will affect > "cle

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Antoine Pitrou
On Fri, 21 Nov 2014 05:47:58 -0800 Raymond Hettinger wrote: > > Another issue is that it breaks the way I and others have taught for years > that generators are a kind of iterator (an object implementing the iterator > protocol) and that a primary motivation for generators is to provide a > si

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Chris Angelico
On Sat, Nov 22, 2014 at 3:37 AM, Donald Stufft wrote: > I don’t have an opinion on whether it’s enough of a big deal to actually > change > it, but I do find wrapping it with a try: except block and returning easier > to understand. If you showed me the current code unless I really thought about

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Donald Stufft
> On Nov 21, 2014, at 11:31 AM, Ethan Furman wrote: > > On 11/21/2014 05:47 AM, Raymond Hettinger wrote: >> >> Also, the proposal breaks a reasonably useful pattern of calling >> next(subiterator) >> inside a generator and letting the generator terminate when the data stream >> ends. >> >>

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Ethan Furman
On 11/21/2014 05:47 AM, Raymond Hettinger wrote: > > Also, the proposal breaks a reasonably useful pattern of calling > next(subiterator) > inside a generator and letting the generator terminate when the data stream > ends. > > Here is an example that I have taught for years: > > def [...]

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Paul Moore
On 21 November 2014 15:58, Steven D'Aprano wrote: >> > def izip(iterable1, iterable2): >> > it1 = iter(iterable1) >> > it2 = iter(iterable2) >> > while True: >> > v1 = next(it1) >> > v2 = next(it2) >> > yield v1, v2 >> >> Is it obviou

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Chris Angelico
On Sat, Nov 22, 2014 at 2:58 AM, Steven D'Aprano wrote: > Since zip() is documented as > halting on the shorter argument, it can't raise an exception. So what > other options are there apart from silently consuming the value? Sure, it's documented as doing that. But imagine something that isn't a

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Steven D'Aprano
On Sat, Nov 22, 2014 at 12:53:41AM +1100, Chris Angelico wrote: > On Sat, Nov 22, 2014 at 12:47 AM, Raymond Hettinger > wrote: > > Also, the proposal breaks a reasonably useful pattern of calling > > next(subiterator) inside a generator and letting the generator terminate > > when the data stream

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Paul Moore
On 21 November 2014 13:53, Chris Angelico wrote: > On Sat, Nov 22, 2014 at 12:47 AM, Raymond Hettinger > wrote: >> Also, the proposal breaks a reasonably useful pattern of calling >> next(subiterator) inside a generator and letting the generator terminate >> when the data stream ends. Here is a

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Chris Angelico
On Sat, Nov 22, 2014 at 12:47 AM, Raymond Hettinger wrote: > Also, the proposal breaks a reasonably useful pattern of calling > next(subiterator) inside a generator and letting the generator terminate > when the data stream ends. Here is an example that I have taught for > years: > > def izi

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-21 Thread Raymond Hettinger
> On Nov 19, 2014, at 12:10 PM, Guido van Rossum wrote: > > There's a new PEP proposing to change how to treat StopIteration bubbling up > out of a generator frame (not caused by a return from the frame). The > proposal is to replace such a StopIteration with a RuntimeError (chained to > the

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Chris Angelico
On Fri, Nov 21, 2014 at 10:34 AM, Chris Angelico wrote: > On Fri, Nov 21, 2014 at 6:36 AM, Guido van Rossum wrote: >> It would also be useful if we could extend the PEP with some examples of the >> various categories of fixes that can be applied easily, e.g. a few examples >> of "raise StopIterat

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Guido van Rossum
On Thu, Nov 20, 2014 at 3:13 PM, Antoine Pitrou wrote: > On Thu, 20 Nov 2014 14:04:24 -0800 > Guido van Rossum wrote: > > > On Thu, Nov 20, 2014 at 12:13 PM, Serhiy Storchaka > > wrote: > > > > > On 20.11.14 21:58, Antoine Pitrou wrote: > > > > > >> To me "generator_return" sounds like the addi

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Chris Angelico
On Fri, Nov 21, 2014 at 9:04 AM, Guido van Rossum wrote: > On Thu, Nov 20, 2014 at 12:13 PM, Serhiy Storchaka > wrote: >> >> On 20.11.14 21:58, Antoine Pitrou wrote: >>> >>> To me "generator_return" sounds like the addition to generator syntax >>> allowing for return statements (which was done as

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Chris Angelico
On Fri, Nov 21, 2014 at 6:36 AM, Guido van Rossum wrote: > It would also be useful if we could extend the PEP with some examples of the > various categories of fixes that can be applied easily, e.g. a few examples > of "raise StopIteration" directly in a generator that can be replaced with > "retu

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Terry Reedy
On 11/20/2014 2:36 PM, Guido van Rossum wrote: There's still a lively discussion on python-ideas; Steven D'Aprano has dug up quite a bit of evidence that StopIteration is used quite a bit in ways that will break under the new behavior, and there also seems to be quite a bit of third-party inform

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Antoine Pitrou
On Thu, 20 Nov 2014 14:04:24 -0800 Guido van Rossum wrote: > On Thu, Nov 20, 2014 at 12:13 PM, Serhiy Storchaka > wrote: > > > On 20.11.14 21:58, Antoine Pitrou wrote: > > > >> To me "generator_return" sounds like the addition to generator syntax > >> allowing for return statements (which was d

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Terry Reedy
On 11/20/2014 5:04 PM, Guido van Rossum wrote: On Thu, Nov 20, 2014 at 12:13 PM, Serhiy Storchaka mailto:storch...@gmail.com>> wrote: On 20.11.14 21:58, Antoine Pitrou wrote: To me "generator_return" sounds like the addition to generator syntax allowing for return st

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Guido van Rossum
On Thu, Nov 20, 2014 at 12:13 PM, Serhiy Storchaka wrote: > On 20.11.14 21:58, Antoine Pitrou wrote: > >> To me "generator_return" sounds like the addition to generator syntax >> allowing for return statements (which was done as part of the "yield >> from" PEP). How about "generate_escape"? >> >

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Serhiy Storchaka
On 20.11.14 21:58, Antoine Pitrou wrote: To me "generator_return" sounds like the addition to generator syntax allowing for return statements (which was done as part of the "yield from" PEP). How about "generate_escape"? Or may be "generator_stop_iteration"? __

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Antoine Pitrou
On Thu, 20 Nov 2014 11:36:54 -0800 Guido van Rossum wrote: > I've made some updates to the PEP: > > - added 19-Nov-2014 to Post-History > - removed "implicitly-raised" from the abstract > - changed the __future__ thing to generator_return To me "generator_return" sounds like the addition to gene

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Guido van Rossum
I've made some updates to the PEP: - added 19-Nov-2014 to Post-History - removed "implicitly-raised" from the abstract - changed the __future__ thing to generator_return - added a clarifying paragraph that Chris added to his own draft - added a link to http://bugs.python.org/issue22906 which has a

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Nick Coghlan
On 20 November 2014 06:15, Benjamin Peterson wrote: > > On Wed, Nov 19, 2014, at 15:10, Guido van Rossum wrote: > > There's a new PEP proposing to change how to treat StopIteration bubbling > > up out of a generator frame (not caused by a return from the frame). The > > proposal is to replace suc

Re: [Python-Dev] PEP 479: Change StopIteration handling inside generators

2014-11-20 Thread Nick Coghlan
On 20 November 2014 06:48, MRAB wrote: > On 2014-11-19 20:10, Guido van Rossum wrote: > >> There's a new PEP proposing to change how to treat StopIteration >> bubbling up out of a generator frame (not caused by a return from >> the frame). The proposal is to replace such a StopIteration with a >>

  1   2   >