On 26 October 2016 at 08:48, Nathaniel Smith <n...@pobox.com> wrote: > If it takes a strong reference, then suddenly we're pinning all > iterators in memory until the end of the enclosing function, which > will often look like a memory leak. I think this would break a *lot* > more existing code than the for-scoped-iterclose proposal does, and in > more obscure ways that are harder to detect and warn about ahead of > time.
It would take a strong reference, which is another reason why close_resources() would be an essential part of the explicit API (since it would drop the references in addition to calling the __exit__() and close() methods of the declared resources), and also yet another reason why you've convinced me that the only implicit API that would ever make sense is one that was scoped specifically to the iteration process. However, I still think the explicit-API-only suggestion is a much better path to pursue than any implicit proposal - it will give folks that see it for the first something to Google, and it's a general purpose technique rather than being restricted specifically to the cases where the resource to be managed and the iterator being iterated over are one and the same object. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/