[Python-Dev] PEP 343 - Abstract Block Redux

Paul Moore p.f.moore at gmail.com
Sat May 14 15:08:30 CEST 2005


On 5/14/05, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Nick Coghlan wrote:
> 
> > PEP 343 (like PEP 310 before it) makes it possible to define the correct
> > resource management *once*, and then invoke it via a 'with' (or 'do')
> > statement.

This is probably the main point for me - encapsulate the try...finally
dance in such a way that the two parts are not separated by an
(arbitrarily long) chunk of code. I hated the equivalent dances in C
(usually malloc/free stuff in that case) and it feels awkward that
this is the one real ugliness of C that Python hasn't fixed for me :-)

> sure, but even if you look at both the application code *and*
> the resource management, there are no clues that the "with"
> statement is really just a masked "try/finally" statement.  just
> look at the generator example:
> 
>     acquire
>     yield
>     release
> 
> what in this snippet tells you that the "release" part will run even if
> the external block raises an exception?

I agree with this point, though. What I liked about the original PEP
340 was the fact that the generator was a template, with "yield"
acting as a "put the block here" placeholder.

> but I still think that something closer to the original PEP 340 is a lot
> more useful.

Overall, I'd agree. I'm still fond of the original PEP 340 in all its
glory - the looping issue was a wart, but PEP 343 seems so stripped
down as to be something entirely different, not just a fix to the
looping issue.

My view - PEP 343 get a +1 in preference to PEP 310.
I'd like to see PEP 342 - that gets a +1 from me.

Covering both these areas at once, PEP 340 would still probably be my
preference, though. (I'm not convinced there's much chance of
resurrecting it, though).

Even it its limited form, I prefer PEP 343 to the status quo, though.

Oh, and I'm leaning towards "with" as a keyword again, as a result of
the "works better with member functions" argument.

Paul.


More information about the Python-Dev mailing list