[Python-ideas] except expression

Jan Kaliszewski zuo at chopin.edu.pl
Wed Feb 19 02:40:38 CET 2014


19.02.2014 02:11, Chris Angelico wrote:

> On Wed, Feb 19, 2014 at 11:19 AM, Jan Kaliszewski <zuo at chopin.edu.pl> 
> wrote:
>> 18.02.2014 17:25, Paul Moore napisał:
>>
>>
>>> OTOH, there's still an argument for only allowing a single 
>>> exception
>>> name in the syntax (an "identifier" rather than an "expression" in
>>> syntax terms). If you must catch multiple exceptions, give the
>>> relevant tuple a name.
>>
>>
>> I believe that at this point (what the exception spec would be
>> allowed to be: identifier?, tuple?, any expression?) the syntax 
>> should
>> be identical to the statement syntax (i.e.: any expression).
>>
>> Less special cases to remember.
>
> Yes, definitely. I see little value in forcing single-exception 
> catching.
>
>> For the same reason, I believe that tuple expressions
>> ("except (ValueError, TypeError)") should be obligatorily
>> enclosed with parens as long as they are obligatorily enclosed
>> with parens in the statement syntax (i.e., probably till Python 3.13
>> :)).
>
> AFAIK, the only reason to mandate the parens is to specifically
> disallow the Py2 syntax:
>
> except Exception, e:
>     pass
>
> If that's the case, they could be optional in the expression form, as
> that has no Py2 equivalent.

But then you must remember: in expression yes, in statement no;
+ additional trouble when you refactor transforming the former to
the latter...

Cheers.
*j



More information about the Python-ideas mailing list