This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dino.viehland
Recipients dino.viehland
Date 2012-08-07.00:16:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344298577.11.0.925171364298.issue15568@psf.upfronthosting.co.za>
In-reply-to
Content
When implementing an iterable object by hand, and raising StopIteration with a value, the value is not provided as the result of the yield from expression.  This differs from the behavior in the "Formal Semantics" section.  Here's an example of how it differs from working with a normal generator:

class C:
    def __iter__(self): return self
    def __next__(self):
            raise StopIteration(100)


def g():
    if False:
        yield 100
    return 100

def f(val):
    x = yield from val
    print('x', x)

list(f(C()))
list(f(g()))


This makes it impossible to wrap a generator in a non-generator and get the same behavior.  The issue seems to be that the yield from implementation calls PyIter_Next which clears the StopIteration exception rather than say directly doing something like "(*iter->ob_type->tp_iternext)(iter);".
History
Date User Action Args
2012-08-07 00:16:28dino.viehlandsetrecipients: + dino.viehland
2012-08-07 00:16:17dino.viehlandsetmessageid: <1344298577.11.0.925171364298.issue15568@psf.upfronthosting.co.za>
2012-08-07 00:16:13dino.viehlandlinkissue15568 messages
2012-08-07 00:16:01dino.viehlandcreate