On 2016-10-25 4:33 AM, Nick Coghlan wrote:
I'm starting to think that we instead need a way
to let them easily say "This resource, the one I just created or have
otherwise gained access to? Link its management to the lifecycle of
the currently running function or frame, so it gets cleaned up when it
finishes running".


But how would it help with a partial iteration over generators
with a "with" statement inside?

   def it():
       with open(file) as f:
           for line in f:
               yield line

Nathaniel proposal addresses this by fixing "for" statements,
so that the outer loop that iterates over "it" would close
the generator once the iteration is stopped.

With your proposal you want to attach the opened file to the
frame, but you'd need to attach it to the frame of *caller* of
"it", right?

Yury
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to