Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76290 > unrolled thread

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

Started byMakoto Kuwata <kwatch@gmail.com>
First post2014-08-14 18:59 +0900
Last post2014-08-14 13:32 +0300
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'? Makoto Kuwata <kwatch@gmail.com> - 2014-08-14 18:59 +0900
    Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'? Marko Rauhamaa <marko@pacujo.net> - 2014-08-14 13:32 +0300

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

FromMakoto Kuwata <kwatch@gmail.com>
Date2014-08-14 18:59 +0900
SubjectRe: [Q] is 'yield from' syntax sugar for 'for'+'yield'?
Message-ID<mailman.12990.1408010368.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On Thu, Aug 14, 2014 at 6:38 PM, Chris Angelico <rosuav@gmail.com> wrote:

> On Thu, Aug 14, 2014 at 7:35 PM, Makoto Kuwata <kwatch@gmail.com> 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 manually, and are simply taken
> care of. Best would be to read the PEP itself:
>
> http://www.python.org/dev/peps/pep-0380/
>
> ChrisA
>

Thank you. It seems too complicated...
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:

   it = iter(xs)
   try:
     while 1:
       yield next(it)
   except StopIteration as ex:
     val = ex.value


Thanks.

--
regards,
kwatch

[toc] | [next] | [standalone]


#76292

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-08-14 13:32 +0300
Message-ID<87oavntl96.fsf@elektro.pacujo.net>
In reply to#76290
Makoto Kuwata <kwatch@gmail.com>:

> 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 spoonfeed a sequence of return values
to the caller. The coroutine meaning of "yield from" has nothing
whatsoever to do about delivering computation results; instead, it
denotes a state where a blocking operation is waited for and the control
is handed off to other activities.



Marko

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web