[Python-ideas] Revised**7 PEP on Yield-From
Jacob Holm
jh at improva.dk
Sat Mar 21 02:04:05 CET 2009
Greg Ewing wrote:
>> Jacob Holm wrote:
>>
>>> The "GeneratorExit", I expect due to the description of close in PEP
>>> 342:
>>>
>>> def close(self):
>>> try:
>>> self.throw(GeneratorExit)
>>> except (GeneratorExit, StopIteration):
>>> pass
>>> else:
>>> raise RuntimeError("generator ignored GeneratorExit")
>
> Hmmm... well, my PEP kind of supersedes that when a yield-from
> is in effect, because it specifies that the subiterator is
> finalized first by attempting to call its 'close' method, not
> by throwing GeneratorExit into it. After that, GeneratorExit is
> used to finalize the delegating generator.
>
> The reasoning is that GeneratorExit is an implementation
> detail of generators, not something iterators in general should
> be expected to deal with.
>
As already mentioned in another mail to this list (maybe you missed
it?), the expansion in your PEP actually has the behaviour you expect
for the GeneratorExit example because GeneratorExit doesn't inherit from
Exception. No need to redefine anything here. Your patch is right, I
was wrong, end of story...
The other mismatch, concerning the missing "close" calls to the
iterator, I still believe to be an issue. It is debatable whether the
issue is mostly with the PEP or the implementation, but they don't match
up as it is...
- Jacob
More information about the Python-ideas
mailing list