[Python-Dev] Request for clarification of PEP 380

Nick Coghlan ncoghlan at gmail.com
Thu Mar 8 15:15:20 CET 2012


On Fri, Mar 9, 2012 at 12:06 AM, Mark Shannon <mark at hotpy.org> wrote:
>> 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.

On the contrary, this question is explicitly addressed in the PEP:
http://www.python.org/dev/peps/pep-0380/#finalization
If you want to block an inadvertent close() call, you need to either
wrap the object so it doesn't implement unwanted parts of the
generator API (which is the iterator protocol plus send(), throw() and
close()), or else you should continue to use simple iteration rather
than delegation.
Cheers,
Nick.
-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /