On Sun, Nov 6, 2016 at 9:38 AM, Nick Coghlan <ncogh...@gmail.com> wrote:

> On 6 November 2016 at 17:18, Ram Rachum <r...@rachum.com> wrote:
> > On Sun, Nov 6, 2016 at 8:53 AM, Nick Coghlan <ncogh...@gmail.com> wrote:
> >> There's still something seriously odd going in relation to your
> >> overall resource management architecture if "cleanup, maybe, unless I
> >> decide to tell you not to" is a behaviour you regularly need. Cleanup
> >> functions in a garbage collected environment should be idempotent, so
> >> it doesn't matter if you redundantly call them again later.
> >
> >
> > Well, you think it's weird that I want a `finally` clause to not be
> called
> > in some circumstances. Do you think it's equally weird to want an
> `__exit__`
> > method that is not called in some circumstances?
>
> Yes, as the whole point of __exit__ is that the interpreter goes to
> great lengths to make sure it always gets called, no matter what else
> happens with the currently executing frame (whether it finishes
> normally, returns early, breaks out of a loop, continues with the next
> iteration, raises an exception, or gets suspended without ever
> resuming normal execution).
>
> If you don't want that behaviour, then __exit__ likely isn't the right
> tool (although it may provide the technical basis for a selective
> cleanup framework).
>
> Cheers,
> Nick.
>
>
I understand your point of view. I see that Python does allow you to not
call `__exit__` if you don't want to, so I wish it'll have the same
approach to not calling `generator.close()` if you don't want to. (This is
what it's really about, not `finally`.)
_______________________________________________
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