[Python-Dev] Request for clarification of PEP 380

Mark Shannon mark at hotpy.org
Thu Mar 8 15:06:17 CET 2012


Hi,

The scenario is this:
A generator, G, has a non-generator sub-iterator, S,
(ie G includes a "yield from S" experssion and S is not a generator)
and either G.close() or G.throw(GeneratorExit) is called.

In the current implementation, S.close() is called and,
if that call raises an exception, then that exception is suppressed.

Should close() be called at all? I know that it helps non-generators
to support the protocol, but there is the problem of iterables that 
happen to have a close method. This may cause unwanted side effects.

Why is the exception suppressed?

The text of the PEP seems to implicitly assume that all sub-iterators
will be generators, so it is not clear on the above points.

Cheers,
Mark.


More information about the Python-Dev mailing list