Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; "subject:' ": 0.07; 'ex:': 0.09; 'pep': 0.09; 'try:': 0.09; 'val': 0.09; 'cc:addr:python-list': 0.11; 'wrote': 0.14; 'propagated': 0.16; 'subject:yield': 0.16; 'xs:': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'thu,': 0.19; 'subject:] ': 0.20; 'aug': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'specifies': 0.24; 'cc:2**0': 0.24; '>': 0.26; '(see': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; 'subject:from': 0.34; 'except': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'yield': 0.36; 'skip:- 10': 0.38; 'pm,': 0.38; 'even': 0.60; 'first': 0.61; 'more': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=a5EDJptoQvS2L2l93Y9R7QOGeHGBXcBLtkqqfObBXBw=; b=T9PBCLBQ/meMKPTk80Q0YRnsD485tDQrmi1C+nwLkOj3MXDj2ja8q/7xGIBtRxLTAm E3NXIh8emvpCsm3VCMYiaaN39ae+DIZfAoCzDR+Hf7jsNvAnf3MD3kMizYnUFhd1IIP5 fSxwUOjl9P0SWS6jyahN0yIc8kuU/5HIrCpvNT/CzlJ6kHJ97ypYn1hv5scz74CVeIky mtJudQnD0qQUZ2Ej0Ru5+wdl9zUNKp/UpzZio+/VwX82ayh/v0ANOG1PDgSaVw1ZRfoB 3TApK2LP9xXz7/bylQW8tB9KciIp5aa1cd2HA8OJsZ2KH1mnzzlNTx3eBF4OlWEGehZH wS3A== MIME-Version: 1.0 X-Received: by 10.42.84.9 with SMTP id j9mr14651645icl.60.1408021063317; Thu, 14 Aug 2014 05:57:43 -0700 (PDT) Sender: kwatch@gmail.com In-Reply-To: References: Date: Thu, 14 Aug 2014 21:57:43 +0900 X-Google-Sender-Auth: FhXDCVQA9rqy9WQO9SAnjsApgiM Subject: Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'? From: Makoto Kuwata To: Chris Angelico Content-Type: multipart/alternative; boundary=90e6ba614d4850c235050096732b Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 82 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408021072 news.xs4all.nl 2942 [2001:888:2000:d::a6]:36862 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76298 --90e6ba614d4850c235050096732b Content-Type: text/plain; charset=UTF-8 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 > > 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 > > It's even more complicated than that. The PEP specifies the exact > semantics. > > ChrisA > Well, I wrote the above code in order to describe `value is propagated by StopIteration' because I misunderstood that it is propagated by return value of yield statement (see my first post). I have known that `yield from` is very complicated (thanks to your reply). -- regards, kwatch --90e6ba614d4850c235050096732b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Thu, Aug 14, 2014 at 7:02 PM, Chris Angelico &= lt;rosuav@gmail.com> wrote:
On Thu, Aug 14, 2014 at 7:59= PM, Makoto Kuwata <kwatch@gmail.com= > wrote:
> I understand that 'val =3D yield from xs' is completely differ= ent from::
>
> =C2=A0 =C2=A0for x in xs:
> =C2=A0 =C2=A0 =C2=A0 ret =3D yield x
> =C2=A0 =C2=A0val =3D x
>
> Return value is propagated by StopIteration, like:
>
> =C2=A0 =C2=A0it =3D iter(xs)
> =C2=A0 =C2=A0try:
> =C2=A0 =C2=A0 =C2=A0while 1:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0yield next(it)
> =C2=A0 =C2=A0except StopIteration as ex:
> =C2=A0 =C2=A0 =C2=A0val =3D ex.value

It's even more complicated than that. The PEP specifies the exact= semantics.

ChrisA
<= div>
Well, I wrote the above code in order to describe `value= is propagated by StopIteration'
because I misunderstood that= it is propagated by return value of yield statement
(see my first post).

I have known that `yield= from` is very complicated (thanks to your reply).

--
regards,
kwatch

--90e6ba614d4850c235050096732b--