Message167591
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);". |
|
Date |
User |
Action |
Args |
2012-08-07 00:16:28 | dino.viehland | set | recipients:
+ dino.viehland |
2012-08-07 00:16:17 | dino.viehland | set | messageid: <1344298577.11.0.925171364298.issue15568@psf.upfronthosting.co.za> |
2012-08-07 00:16:13 | dino.viehland | link | issue15568 messages |
2012-08-07 00:16:01 | dino.viehland | create | |
|