[Python-ideas] except expression

Rob Cliffe rob.cliffe at btinternet.com
Wed Feb 19 02:59:42 CET 2014


On 19/02/2014 01:40, Jan Kaliszewski wrote:
> 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.
Uh yes.  I thought/hoped the debate had got past this point.
>>
>>> 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
>>> :)).
>>
I think I agree on grounds of (sorry if I'm becoming a bore, but you 
guessed it!) Consistency!  But I don't see this as a critical issue, 
particularly as Python 3.13 is probably a few weeks away :-) .  I think 
putting parens around a list of exceptions would be good style in any case.
Rob Cliffe
>> 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
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2012.0.2247 / Virus Database: 3705/6604 - Release Date: 02/18/14



More information about the Python-ideas mailing list