On Sun, 15 May 2005, Guido van Rossum wrote:
> In rev 1.10 I moved the __enter__ call out of the
> try-block again. Having it inside was insane: when __enter__ fails, it
> should do its own cleanup rather than expecting __exit__ to clean up
> after a partial __enter__.

No, it wasn't insane.  You had a good reason for putting it there.

The question is what style of implementation you want to encourage.

If you put __enter__ inside, then you encourage idempotent __exit__,
which makes resource objects easier to reuse.

If you put __enter__ outside, that allows the trivial case to be
written a little more simply, but also makes it hard to reuse.


-- ?!ng
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to