[Python-ideas] Yield-From: Finalization guarantees
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Mar 31 05:25:37 CEST 2009
Jacob Holm wrote:
> in most cases this will be code that is breaking the rule about
> not catching KeyboardInterrupt and SystemExit.
Not necessarily, it could be doing
except GeneratorExit:
return
> If you use such a generator in a yield-from
> expression, you will get a RuntimeError('generator ignored
> GeneratorExit') on close, telling you that something is wrong.
But it won't be at all clear *what* is wrong or what to
do about it. The caller is making a perfectly ordinary
yield-from call, and he's calling what looks to all the
world like a perfectly well-behaved iterator. Where's
the mistake?
Remember that the generator being called may have been
written by someone else. The caller may not know anything
about its internals or be in a position to fix them if
he did.
> I think that getting a RuntimeError on close is sufficient indication
> that such a generator should not be used in yield-from.
But it's a perfectly valid generator by current standards.
I don't want to declare some existing class of generators
as being second-class citizens with respect to yield-from,
especially based on some internal implementation detail
unknowable to its caller.
--
Greg
More information about the Python-ideas
mailing list