[Python-3000] Exceptions internals and removing sys.exc_*

Collin Winter collinw at gmail.com
Tue Jan 23 23:07:13 CET 2007


On 1/23/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> On 1/23/07, Thomas Wouters <thomas at python.org> wrote:
> > On 1/23/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> > > Sorry, for those of us following along at home ;-) could someone
> > > explain why we couldn't just introduce a ``sys.get_exception()`` or
> > > something like that which would then make the exception (and therefore
> > > the traceback) available?
> >
> > We could, of course, but what's the point? To rename the existing 'exc_info'
> > into 'get_exception' and some attribute-retrieval? I'm all for cleanup and
> > not looking back, but that's quite a lot of gratuitous breakage, to little
> > point. I don't consider it 'weird' or 'bad' or 'a wart' or 'a hysterical
> > raisin' that sys.exc_info() returns a tuple of three things.
>
> If I understand it right, all three elements of the sys.exc_info()
> tuple are derivable from only the middle element (at least in Python
> 3.0 where the middle element would always have to be an exception
> instance[1])::
>
>     def exc_info():
>         exc = sys.get_exception()
>         return exc.__class__, exc, exc.__traceback__
>
> So I guess it just seems a little redundant to return a tuple of three
> things when two of the three are easily derivable from the third.  I
> was trying to think of any other API in Python which does something
> like this, but I couldn't find one...

It strikes me as a redundant, too, but I'm -1 on dropping
sys.exc_info() entirely in 3.0 (at least not without a deprecation
period in 2.x). While a fixer for 2to3 to convert sys.exc_info() calls
into sys.get_exception() terms would be pretty trivial, that doesn't
cover converting all the functions that expect an exc_info() tuple as
arguments, nor does it cover all the necessary documentation changes.

Collin Winter


More information about the Python-3000 mailing list