[Python-3000] Problem with grammar for 'except'?

Guido van Rossum guido at python.org
Thu Sep 4 21:36:12 CEST 2008


On Wed, Sep 3, 2008 at 9:25 PM, Raymond Hettinger <python at rcn.com> wrote:
> [Brett]
>>
>> I gave a talk last night at the Vancouver Python users group on
>> 2.6/3.0, and I tried the following code and it failed during a live
>> demo::
>>
>>  >>> try: pass
>>  ... except Exception, Exception: pass
>>   File "<stdin>", line 2
>>     except Exception, Exception: pass
>>                                ^
>>  SyntaxError: invalid syntax
>>
>> Now from what I can tell from PEP 3110, that should be legal in 3.0.
>> Am I reading the PEP correctly?
>
> Don't think so.
> The parens are necessary for a tuple of exceptions
> lest it be confused with the old "except E, v" syntax
> which meant "except E as e".
>
> Maybe in 3.1, the paren requirement can be dropped.

I would wait longer -- until well after the 2.x line is dead and
buried. It will take some time for every Python user to train their
Python fingers not to type "except E, v:" and we don't want people who
are late in migrating inserting bugs like this in their first 3.x
program.

> But for 3.0, it would be a problem given that old
> scripts would start getting misinterpreted.
>
> I did something similar for list.sort() by requiring
> keyword arguments.  That way, we wouldn't have
> list.sort(f) running with f as a cmp function 2.6 and
> as a key function in 3.0.
>
>
> Raymond
>
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/guido%40python.org
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list