[Python-3000] Transition to Python 3's raise syntax

Collin Winter collinw at gmail.com
Sat Feb 24 22:27:43 CET 2007


(Finally getting back around to this)

On 2/9/07, Phillip J. Eby <pje at telecommunity.com> wrote:
[snip]
> 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.

What do you mean by "new-style" and "old-style except: clauses"? Are
"new-style" except clauses the ones spelled "except E as NAME" while
"old-style" ones are spelled "except E, NAME"?

> 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.

Clear enough.

> 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.

What happens in this case:

e = Exception()
e.__traceback__ = T1
raise Exception, e, T2

Which traceback takes precedence? My preference would be to raise an
exception in this case.

Collin Winter


More information about the Python-3000 mailing list