[Python-Dev] PEP 343 rewrite complete

Phillip J. Eby pje at telecommunity.com
Wed Jun 1 22:26:44 CEST 2005


At 10:00 PM 6/1/2005 +0200, Eric Nieuwland wrote:
>Phillip J. Eby wrote:
> > At 08:46 PM 6/1/2005 +0200, Eric Nieuwland wrote:
> >> If I look at the translation it an augmented 'try'.
> >>         with EXPR as VAR:
> >>                 BLOCK1
> >>         except EXCEPTION:
> >>                 BLOCK2
> >> could then be translated to
> >
> > -1, too confusing.
>
>A matter of taste, I guess. IMHO 'with' secretly handling exceptions is
>confusing.

It doesn't secretly handle them; it simply gets access to them, which is an 
entirely different thing.

By confusing, I mean that it is not clear from your construct what 
exceptions are caught by the 'except' clause, due to its structural 
layout.  It's also not clear whether the __enter__/__exit__ of EXPR wrap 
BLOCK1 only, or both BLOCK1 and BLOCK2.  These aspects are "confusing" 
because whatever decision you make about the semantics, someone will have 
to *remember* them, as opposed to being unambiguously represented by the 
block structure.

By contrast, if you remove the except: clause from your construct, it is 
clear that BLOCK1 is what is wrapped, and there is no possible confusion 
about who sees what exceptions.  Exceptions inside the block are 
communicated to __exit__, exceptions outside (including those in the 'with' 
statement itself) are not.



More information about the Python-Dev mailing list