10 Sep
2008
10 Sep
'08
2:27 p.m.
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: import types 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?