[Python-3000] How far to go with cleaning up exceptions

Collin Winter collinw at gmail.com
Sat Mar 3 01:39:51 CET 2007


On 3/1/07, Brett Cannon <brett at python.org> wrote:
> I spent my sprint time cleaning up exceptions for Py3K and Guido
> suggested I run some things by the group to make sure they don't make
> transitioning from 2.6 too difficult.  After adding the proper
> restrictions in terms of what can and cannot be raised or caught, I
> began cleaning up BaseException's API per PEP 352.
>
> First thing I did was remove slicing.  That wasn't too bad since I
> just got exceptions about the lack of __getitem__ and went to the
> affected line and tossed in '.args' between the index and the
> exception.  Not sure if 2to3 can handle this as it would need to
> realize when an exception is within scope and then insert '.args' when
> it is be indexed on.

2to3 currently cannot handle this. 2.6's "py3k-compat" mode could
handle it easily, though.

> The next thing I did was strip out the use of '.args' and make
> BaseException take a single argument that gets assigned to 'message'.
> The fruits of this labour are in the p3yk_no_args_on_exc branch.  This
> one turned out to be a pain in the rear.
[snip]

I took at stab at this same conversion a few weeks ago and had the
exact same experience. I ended up resolving my frustration by applying
"svn revert" and working on something else : )

I think this will shape up to be one of the harder parts of porting
from 2.x to 3.0.

> As for transforming the 'args' accesses to something else,
> I guess 2to3 could automatically do 'args[0]' accesses to 'message',
> but anything else will need to be changed by hand.

There's very little 2to3 can do on this front. I think 2.6's
py3k-compat flag is going to be the best bet for this particular
conversion.

Collin Winter


More information about the Python-3000 mailing list