[Python-Dev] Py3k: Except clause syntax

Georg Brandl g.brandl at gmx.net
Fri Mar 17 22:21:26 CET 2006


Brett Cannon wrote:
> On 3/17/06, Georg Brandl <g.brandl at gmx.net> wrote:
>> John J Lee wrote:
>>
>> >> In your formulation the comma binds more tightly than the as keyword.
>> >> In import statements it's the other way around.  That seems like it
>> >> might be a source of confusion.
>> >
>> > Perhaps parentheses around the exception list should be mandatory for the
>> > 2-or-more exceptions case?
>> >
>> > except NameError as e:                  --> fine
>> > except (NameError) as e:                --> fine
>> > except (NameError,) as e:               --> fine
>> >
>> > except NameError, OtherError as e:      --> SyntaxError
>> > except (NameError, OtherError) as e:    --> fine
>>
>> I don't like that particularly, but I guess that for consistency's sake
>> it would have to be done this way.
>>
> 
> I don't like it period.  What consistency problem is there?  This is
> Python 3 we are talking about, so if something makes good sense such
> as not having parentheses, I say leave them off.  There are multiple
> places where parens could be required but are not, like multiple
> assignment.

I only think of consistency with the usage of "as" in the import statement.
I know how it works, but I predict people will come and write

except NameError as e, OtherError as f:

Georg



More information about the Python-Dev mailing list