[Python-Dev] Py3k: Except clause syntax

skip at pobox.com skip at pobox.com
Sun Mar 19 04:47:17 CET 2006


    Greg> On the other hand, in

    Greg>    except E1, E2 as e:

    Greg> the E1, E2 is just a tuple expression, so it's
    Greg> exactly equivalent to

    Greg>    except (E1, E2) as e:

The comma and "as" have different precedence in your proposed except clause
than they currently do in the import statement.  I think that can lead to
confusion.  In particular, if someone is used to

    from foo import bar, baz as flurp

I think they might expect that in this try/except statement:

    try:
        something()
    except E1, E2 as e
        print "something bad happened"

if E1 is raised, e will not be (re)bound, but if E2 is raised, then it will
be.  I know Python is not as heavily an operator-oriented language as C or
Perl, but I think it makes sense to maintain the same relative binding
precedence between operators in different contexts wherever possible.

There seem to be other places where Python is beginning to require parens
even though they aren't strictly necessary to resolve syntactic ambiguity.
This might be one of them.

Skip


More information about the Python-Dev mailing list