[Python-Dev] PEP 343 rewrite complete

Eric Nieuwland eric.nieuwland at xs4all.nl
Thu Jun 2 22:04:20 CEST 2005


Phillip J. Eby wrote:
> At 10:00 PM 6/1/2005 +0200, Eric Nieuwland wrote:
>> Phillip J. Eby wrote:
>> > -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.

OK. This forwarding (is that the proper expression here?) of an 
exception to __exit__ is what I meant by 'secretly handling'.

If everybody agrees I'll write
	with EXPR as VAR:
		try:
			BLOCK1
		except EXCEPTION:
			BLOCK2
instead. Seems a waiste to me, though.
I was thinking about 'try EXPR [as VAR]:' as a 'try' that handles 
uncaught exceptions by forwarding it to EXPR's __exit__ method. No 
confusion with me.

--eric



More information about the Python-Dev mailing list