Re: Reducing "yield from" overhead in recursive generators

2022-03-22 Thread Greg Ewing
On 23/03/22 11:44 am, Rathmann wrote: So that sounds like the original CPython implementation had an O(depth) component, but with a lower constant factor than the current version? Yes, but so much lower that I would expect it to be unmeasurable. -- Greg -- https://mail.python.org/mailman/list

Re: Reducing "yield from" overhead in recursive generators

2022-03-22 Thread Rathmann
> On 19 Mar 2022, at 03:07, Greg Ewing wrote: > > On 19/03/22 9:40 am, Rathmann wrote: >> The other challenge/question would be to see if there is a way to implement >> this basic approach with lower overhead. > > My original implementation of yield-from didn't

Re: Reducing "yield from" overhead in recursive generators

2022-03-19 Thread Barry
> On 19 Mar 2022, at 03:07, Greg Ewing wrote: > > On 19/03/22 9:40 am, Rathmann wrote: >> The other challenge/question would be to see if there is a way to implement >> this basic approach with lower overhead. > > My original implementation of yield-from didn

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Chris Angelico
On Sat, 19 Mar 2022 at 14:06, Greg Ewing wrote: > > On 19/03/22 9:40 am, Rathmann wrote: > > The other challenge/question would be to see if there is a way to implement > > this basic approach with lower overhead. > > My original implementation of yield-from didn't ha

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Greg Ewing
On 19/03/22 9:40 am, Rathmann wrote: The other challenge/question would be to see if there is a way to implement this basic approach with lower overhead. My original implementation of yield-from didn't have this problem, because it didn't enter any of the intermediate frames -- i

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Rathmann
toon. I was not aware of macropy. It certainly seems like a macro could automate the process of switching the "yield from" to yield forms. That is already pretty easy to do by hand, though. The driver itself could be packaged as a decorator using just the facilities available in regular Pyt

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Antoon Pardon
ration: stack.pop() if len(stack) == 0: return ``` and the modified tree traverser is just ```python def inorder_traverse_mod(node): """ONLY for use with recursive_generator_driver""" k, l, r = node if l:

Reducing "yield from" overhead in recursive generators

2022-03-17 Thread Rathmann
the "yield from" syntax which provides a technique for generators to delegate to other generators, including recursively. The trouble is that recursion and generators don't necessarily play all that well together from a performance point of view. As Greg Ewing noted in PEP 380:

Re: yield from () Was: Re: weirdness with list()

2021-03-12 Thread Thomas Jollans
On 03/03/2021 01:01, Cameron Simpson wrote: On 02Mar2021 15:06, Larry Martell wrote: I discovered something new (to me) yesterday. Was writing a unit test for generator function and I found that none of the function got executed at all until I iterated on the return value. Aye. Generators are

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Chris Angelico
over > >>> the subboxes. For MDAT that is implemented like this: > >>> > >>> def __iter__(self): > >>> yield from () > >> > >> Sorry, a bit OT but I'm curious. I haven't seen > >> this before: > >>

Re: yield from () Was: Re: weirdness with list()

2021-03-11 Thread Serhiy Storchaka
t;>> >>> def __iter__(self): >>> yield from () >> >> Sorry, a bit OT but I'm curious. I haven't seen >> this before: >> >> yield from () >> >> What is it doing? >> What do the () represent in this context? > >

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 02Mar2021 15:06, Larry Martell wrote: >I discovered something new (to me) yesterday. Was writing a unit test >for generator function and I found that none of the function got >executed at all until I iterated on the return value. Aye. Generators are lazy - they don't run at all until you ask f

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Larry Martell
> > > the subboxes. For MDAT that is implemented like this: > > > > > > def __iter__(self): > > > yield from () > > > > Sorry, a bit OT but I'm curious. I haven't seen > > this before: > > > > yield from () >

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Marco Sulla
On Mon, 1 Mar 2021 at 19:51, Alan Gauld via Python-list wrote: > Sorry, a bit OT but I'm curious. I haven't seen > this before: > > yield from () > > What is it doing? > What do the () represent in this context? It's the empty tuple. -- https://mail.python.org/mailman/listinfo/python-list

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Chris Angelico
__iter__(self): > > yield from () > > Sorry, a bit OT but I'm curious. I haven't seen > this before: > > yield from () > > What is it doing? > What do the () represent in this context? > It's yielding all the elements in an empty tuple. W

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Alan Gauld via Python-list
On 28/02/2021 23:47, Alan Gauld via Python-list wrote: > On 28/02/2021 00:17, Cameron Simpson wrote: > >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter_

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Chris Angelico
On Wed, Mar 3, 2021 at 8:21 AM Dieter Maurer wrote: > > Alan Gauld wrote at 2021-2-28 23:47 +0000: > >yield from () > > "yield from iterator" is similar to "for i in iterator: yield i" (with > special handling when data/exceptions are injected into the g

yield from () Was: Re: weirdness with list()

2021-03-02 Thread Dieter Maurer
Alan Gauld wrote at 2021-2-28 23:47 +: >yield from () "yield from iterator" is similar to "for i in iterator: yield i" (with special handling when data/exceptions are injected into the generator). Thus, "yield from ()" does essentially nothing with th

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Peter Otten
On 01/03/2021 00:47, Alan Gauld via Python-list wrote: On 28/02/2021 00:17, Cameron Simpson wrote: BUT... It also has a __iter__ value, which like any Box iterates over the subboxes. For MDAT that is implemented like this: def __iter__(self): yield from () Sorry, a bit OT but

Re: yield from () Was: Re: weirdness with list()

2021-03-02 Thread Cameron Simpson
On 28Feb2021 23:47, Alan Gauld wrote: >On 28/02/2021 00:17, Cameron Simpson wrote: >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter__(self): >> yield f

yield from () Was: Re: weirdness with list()

2021-03-01 Thread Alan Gauld via Python-list
On 28/02/2021 00:17, Cameron Simpson wrote: > BUT... It also has a __iter__ value, which like any Box iterates over > the subboxes. For MDAT that is implemented like this: > > def __iter__(self): > yield from () Sorry, a bit OT but I'm curious. I haven't

Re: yield from

2020-03-24 Thread Chris Angelico
On Wed, Mar 25, 2020 at 10:08 AM Dan Stromberg wrote: > > Some time ago, when I first heard about yield from, it wasn't faster than a > for loop yielding. > > Has that improved? It's not about speed. It's about correctness, and the way it delegates everything, no

yield from

2020-03-24 Thread Dan Stromberg
Some time ago, when I first heard about yield from, it wasn't faster than a for loop yielding. Has that improved? -- https://mail.python.org/mailman/listinfo/python-list

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Steven D'Aprano
Makoto Kuwata wrote: > Question about 'yield from'. > > I understand that:: > > yield from xs > > is syntax suger of:: > > for x in xs: > yield x Not quite syntactic sugar. For simple cases, it does exactly the same thing. For more co

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Makoto Kuwata
On Thu, Aug 14, 2014 at 7:02 PM, Chris Angelico wrote: > On Thu, Aug 14, 2014 at 7:59 PM, Makoto Kuwata wrote: > > I understand that 'val = yield from xs' is completely different from:: > > > >for x in xs: > > ret = yield x > >va

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Marko Rauhamaa
Makoto Kuwata : > Thank you. It seems too complicated... I recommend you stop trying to associate the "old" yield with the "new" yield. Asyncio coroutines "abuse" "yield from" for a specific effect. The classic purpose of "yield" was to spo

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Chris Angelico
On Thu, Aug 14, 2014 at 7:59 PM, Makoto Kuwata wrote: > I understand that 'val = yield from xs' is completely different from:: > >for x in xs: > ret = yield x >val = x > > Return value is propagated by StopIteration, like: > >i

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Marko Rauhamaa
Makoto Kuwata : > val = yield from xs > > is same as:: > > for x in xs: > ret = yield x > val = ret > > Is it true? Do I understand correctly? The return value is not one of the yielded values. Instead, it's the value returned by the genera

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Makoto Kuwata
On Thu, Aug 14, 2014 at 6:38 PM, Chris Angelico wrote: > On Thu, Aug 14, 2014 at 7:35 PM, Makoto Kuwata wrote: > > I understand that:: > > > > yield from xs > > > > is syntax suger of:: > > > > for x in xs: > > yield x > >

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Chris Angelico
On Thu, Aug 14, 2014 at 7:35 PM, Makoto Kuwata wrote: > I understand that:: > > yield from xs > > is syntax suger of:: > > for x in xs: > yield x Not just. It's like that for simple cases, but there are edge cases that are much more complicated to do m

[Q] is 'yield from' syntax sugar for 'for'+'yield'?

2014-08-14 Thread Makoto Kuwata
Question about 'yield from'. I understand that:: yield from xs is syntax suger of:: for x in xs: yield x And:: val = yield from xs is same as:: for x in xs: ret = yield x val = ret Is it true? Do I understand correctly? quote from https://docs.

PEP 380 - the 'yield from' proposal

2010-10-15 Thread Hallvard B Furuseth
Regarding http://www.python.org/dev/peps/pep-0380/, "Syntax for Delegating to a Subgenerator": The first call can only be .next(), there's no way to provide an initial value to .send(). That matches common use, but an initial .send() is possible if .next() was called before &quo