[Python-3000] Pre-peps on raise and except changes
Phillip J. Eby
pje at telecommunity.com
Sat Feb 10 01:50:58 CET 2007
At 01:33 PM 2/10/2007 +1300, Greg Ewing wrote:
>Collin Winter wrote:
>
> > I believe the original proposal was something like
> >
> > raise E(V).with_traceback(T)
>
>Does this mean you're not intending to have any syntactic
>variant of the raise statement that includes a traceback
>in 3.0?
That *is* the variant. ;)
>Or is this just so that forward-compatible code
>can be written in 2.6?
Actually, forward compatible code would be easier with something syntactic,
like your 'raise e with t' idea. It would allow the implementation to be
different in 2.6 and 3.0, while using the same syntax. (In 2.6 it could
use the existing machinery, while in 3.0 it could call the
.with_traceback() method.
Hm. Actually, that's not necessary. We could include .with_traceback(T)
in 2.6, and just have old-style except: clauses delete the traceback from
the returned objects. New-style except: clauses would work just as they
would in 3.0.
To summarize, in 2.6 we could support .with_traceback() and create
exception instances with traceback attributes, but the old-style except:
clauses could discard them to prevent cycles. Raising an exception
instance with a __traceback__ attribute would get some special handling so
that it's equivalent to 3-argument raise in today's Python. Likewise,
generator.throw() would need the same special handling in 2.6. Meanwhile,
sys.exc_info() still lives in both versions.
To write 3.0-compatible code, you just use the 3.0 spellings of raise,
throw(), and except. Sounds like a plan!
More information about the Python-3000
mailing list