[Python-ideas] except expression

Jan Kaliszewski zuo at chopin.edu.pl
Sun Feb 16 23:55:46 CET 2014


16.02.2014 23:33, Greg Ewing wrote:

>> On Mon, Feb 17, 2014 at 7:39 AM, Jan Kaliszewski <zuo at chopin.edu.pl> 
>> wrote:
>>
>>>Sorry, I don't catch the point.  If I needed to use a complex
>>>exception spec (a tuple-like) and/or a tuple as the "default"
>>>expression -- I'd just do it:
>>>
>>>    some_io() except (FileNotFoundError: (1, 2, 3),
>>>                      (ValueError, TypeError): 'spam')
>>>
>>>I see no ambiguity here.
>
> To make it parseable, it would probably be necessary to disallow
> commas in the expression following the colon (i.e. it would
> be a 'test' rather than a 'testlist' in terms of the grammar).

I believe that it would be somehow similar to what is allowed to
be keys and values in dict literals (of course modulo the fact
that here only except-like exception specification is allowed
as a "key" [exception class or tuple of exception classes],
and that an additional optional 'as' clause can be used...).

In a way, it can be seen as a *kind of* mapping: expression
specs to "default" values...  So *some* similarity to a dict
literal is not a completely random accident.

Cheers.
*j



More information about the Python-ideas mailing list