---------- Forwarded message ---------- From: Zaur Shibzoukhov firstname.lastname@example.org Date: 2008/9/10 Subject: Re: [Python-ideas] should there be a difference between generators and iterators? To: Bruce Frederiksen email@example.com
I think it should be as
types.GeneratorType.__enter__ = MethodType(lambda self: self, types.GeneratorType) types.GeneratorType.__exit__ = MethodType(lambda self: self.close(), types.GeneratorType)
So that the objects returned by his generator functions (functions
have context manager capability?
2008/9/10 Bruce Frederiksen firstname.lastname@example.org:
Zaur Shibzoukhov wrote:
Bruce Frederiksen wrote:
Since there is no need to clean up after iterators in general, but only for generators specifically; and since the BDFL has nixed my point #5, it makes sense to only add the __enter__ and __exit__ to generators. (And, by extension, itertools).
It makes more sense to allow extending of builtin types in order to support different protocols (not only protocol for "with" statement)
Do you mean the python programmer should do:
types.GeneratorType.__enter__ = lambda self: self types.GeneratorType.__exit__ = lambda self: self.close()
So that the objects returned by his generator functions (functions containing 'yield') have context manager capability?