[Python-Dev] Pre-PEP: Unifying try-except and try-finally
Guido van Rossum
gvanrossum at gmail.com
Fri May 6 16:51:03 CEST 2005
[Nick Coghlan]
>
> > What does a try statement with neither an except clause nor a finally clause mean?
[Greg Ewing]
> I guess it would mean the same as
>
> if 1:
> ...
>
> Not particularly useful, but maybe it's not worth complexifying
> the grammar just for the sake of disallowing it.
>
> Also, some people might find it useful for indenting a block
> of code for cosmetic reasons, although that could easily
> be seen as an abuse...
I strongly disagree with this. It should be this:
try_stmt: 'try' ':' suite
(
except_clause ':' suite)+
['else' ':' suite] ['finally' ':' suite]
|
'finally' ':' suite
)
There is no real complexity in this grammar, it's unambiguous, it's an
easy enough job for the code generator, and it catches a certain class
of mistakes (like mis-indenting some code).
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list