[Python-3000] exception info [was: Discussions with no PEPs] (original) (raw)

Guido van Rossum guido at python.org
Wed Mar 14 01:10:12 CET 2007


[adding back the list]

On 3/13/07, Josiah Carlson <jcarlson at uci.edu> wrote:

What if the thing to the right of 'as' were assigned different values depending on what it was? If it were one name, it would be the exception (without traceback) "except ... as foo". If it was a 3-tuple of names, it would get all three: "except ... as ecls, e, tb:". (with 2, maybe e and tb) Anything else could raise a SyntaxError during the code generation phase.

In cases where we get a tb, we can clear the traceback at the end of the except clause without needing to clear the exception, etc. Whether or not the traceback exists as an attribute of the exception would then become an implementation detail. For cases where we pass an exception instance around, I would introduce a function called gettb(e) (in either sys or traceback) that takes the exception object and returns the traceback. Whether or not it should print a warning unless the keyword-only argument of 'yesIknowIneedtoclearthetraceback' is provided and is True, or if it returns a weakref, I'll leave to someone else's discretion.

That sounds like too much complexity (both the syntax proposal and the get_tb() API). With the new GC, clearing the traceback is really not all that important any more except in the vicinity of buggy code that expects that leaving a scope GC's its locals; apart from that it's more of a performance issue than anything else, so I don't see why we can't just have traceback on the exception object.

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



More information about the Python-3000 mailing list