[Python-Dev] PEP 343 - Abstract Block Redux
Ka-Ping Yee
python-dev at zesty.ca
Mon May 16 07:30:58 CEST 2005
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
More information about the Python-Dev
mailing list