[Python-Dev] Acquire/release functionality (Was: Extended Function syntax)

Alex Martelli aleax@aleax.it
Mon, 3 Feb 2003 14:50:42 +0100


On Monday 03 February 2003 02:02 pm, Moore, Paul wrote:
   ...
> Actually, it's clear to me that the controversial issues are:
>
> 1. Multiple expressions in one with clause
> 2. Exception handling
>
> Maybe the simplest answer is to remove both of these options, and stick
> with a slimmed down version which does gthe basics well. Does anyone have
> a good use case for either of these features?

I can think of no use case for 1. that would not be handled just about as
well by nesting 'with' statements.  I don't like deep nesting any more than
you do, but I suspect the typical nesting of with's won't be any more
problematic than for any other existing kind of statement.

For 2., I'm thinking of something that's able to automatically perform some
call such as db.transaction("rollback") in case of any exception, and maybe 
some other call such as db.transaction("commit") iff no exception occurred.
I.e. an encapsulated equivalent of a try/except/else.  Probably not as
frequent as the need for an encap.equiv. of a try/finally -- and, as usual,
not trivial to decide how best to combine the two needs -- but, it seems
to me that use cases for both situations exist:
  2a, try/finally equivalent: execute cleanup code no matter what,
  2b, try/except/else: execute different code with vs without exceptions


Alex