[Python-Dev] PEP 343 - Abstract Block Redux

Nick Coghlan ncoghlan at gmail.com
Mon May 16 00:18:57 CEST 2005


Paul Moore wrote:
> Looping is definitely a wart. Looping may even be a real problem in
> some cases. There may be cases where an explicit try...finally remains
> better, simply to avoid an unwanted looping behaviour.

I agree PEP 343 throws away too much that was good about PEP 340 - that's why 
I'm still updating PEP 3XX as the discussion continues.

But is there anything PEP 340 does that PEP 3XX doesn't, other than letting you 
suppress exceptions?

The only example the latest version of PEP 3XX drops since the original PEP 340 
is auto_retry - and that suffers from the hidden control flow problem, so I 
doubt Guido would permit it, even *if* the new statement was once again a loop. 
And if the control flow in response to an exception can't be affected, it 
becomes even *harder* to explain how the new statement differs from a standard 
for loop.

 > But I'll live with that to get back the enthusiasm for a new feature
 > that started all of this. Much better than the current "yes, I guess
 > that's good enough" tone to the discussion.

I think the current tone is more due to the focus on addressing problems with 
all of the suggestions - that's always going to dampen enthusiasm.

Every PEP 340 use case that doesn't involve suppressing exceptions (i.e. all of 
them except auto_retry) can be written under the current PEP 3XX using 
essentially *identical* generator code (the only difference is the 
statement_template decorator at the top of the generator definition)

Pros of PEP 3XX 1.6 vs PEP 340:
  - control flow is easier to understand
  - can use inside loops without affecting break/continue
  - easy to write enter/exit methods directly on classes
  - template generators can be reused safely
  - iterator generator resource management is dealt with

Cons of PEP 3XX 1.6 vs PEP 340:
  - no suppression of exceptions (see first pro, though)

Of course, I may be biased :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list