[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Sun Feb 16 23:45:09 CET 2014


On Mon, Feb 17, 2014 at 9:33 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> 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).

Do you mean that there may not be a comma, or that commas must be
surrounded by parens? I wouldn't mind *too* much if it's the latter,
but I still think this could be confusing. Imagine if the exception
list isn't literals, but comes from somewhere else (which is perfectly
legal). How do you eyeball it and see that this is now a new except
clause?

ChrisA


More information about the Python-ideas mailing list