[Python-Dev] Where to put the interrupt module?

Guido van Rossum guido@python.org
Fri, 13 Jun 2003 11:06:02 -0400


> This just reminded me of a question that has been floating around in my
> brain for a while.  Why doesn't Python support the following fully general
> syntax for try-blocks:
> 
>   try:
>     foo()
>   except blah:
>     ...
>   except:
>     ...
>   else:
>     ...
>   finally:
>     ...
> 
> I keep having to write:
> 
>   try:
>     try:
>       foo()
>     except blah:
>       ...
>     except:
>       ...
>     else:
>       ...
>   finally:
>     ...

At some early point in Python's development, it did support this.  I
decided to take it out for two reasons: (1) There were so many cases
that I couldn't manage to create correct code; (2) the semantics
aren't clear: does an exception raised in any of the except clauses
jump to the finally clause or not?  I'd say it should, but it may not
be clear to users (because the except clauses don't apply to each
other).  It also complicates the bytecode generation: effectively, the
compiler has to generate the bytecode equivalent to the second form.
The second form makes this explicitly clear.

Anyway, I don't think I've seen many too many cases where this would
have saved an indentation level.

--Guido van Rossum (home page: http://www.python.org/~guido/)