[Python-ideas] Yield-From: Finalization guarantees
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Mar 25 07:38:26 CET 2009
Nick Coghlan wrote:
> Greg Ewing wrote:
>
>>(1) In non-refcounting implementations, subiterators
>>are finalized promptly when the delegating generator
>>is explicitly closed.
>>
>>(2) Subiterators are not prematurely finalized when
>>other references to them exist.
>
> If you choose (2), then (1) is trivial to implement
>
> with contextlib.closing(make_subiter()) as subiter:
> yield from subiter
That's a fairly horrendous thing to expect people to
write around all their yield-froms, though. It also
means we would have to say that the inlining principle
only holds for refcounting implementations.
Maybe we should just give up trying to accommodate
shared subiterators. Is it worth complicating
everything for the sake of something that's not
really part of the intended set of use cases?
> Hmm, that does suggest another issue with the PEP however: it only calls
> the subiterator's throw with the value of the thrown in exception. It
> should be using the 3 argument form to avoid losing any passed in
> traceback information.
Good point, I'll update the expansion accordingly.
--
Greg
More information about the Python-ideas
mailing list