[Python-Dev] Deprecating string exceptions

Guido van Rossum guido@python.org
Fri, 05 Apr 2002 21:02:01 -0500


> There's no urgency at all but a bug report isn't the right place for
> the discussin, nor is our group's private email.  I didn't think
> that raising the question in the appropriate forum constituted
> emergency action :-).

One of your messages sounded like you were impatiently waiting to
commit your change, and I wondered why that was.

>   GvR> I don't think the patch is ready yet, see my comment on SF.  If
>   GvR> we decide that anything needs to be done in this area I want to
>   GvR> look at it first, so please don't check anything in yet.
> 
> Did I miss the consensus on inheriting from Exception?  I tried to
> review the earlier thread, but the early stuff didn't have much on
> Exception and the later stuff seemed to be about documentation.  So it
> must be buried in the middle if it's there :-).
> 
> At any rate, I don't understand why it is helpful for classes to
> inherit from exception.

There are different views on this, but fact is that we've documented
this as a recommendation since class exceptions were first introduced,
and I've certainly considered starting to warn about exceptions raised
or tested for that are *not* subclasses of Exception.

There was some discussion that concluded that it was a useful feature
(e.g. because the Exception class defines a standard signature and
some standard attributes), and it was even suggested that in the
future the traceback could be stored on the exception instance rather
than in a separate variable.  This would pave the way to deprecating
sys.exc_info().  I kind of like that idea, so I am all for striving to
enforce this in the future.

> I am also curious -- this is off-topic for exceptions -- what the
> right way to check for a new-style class is?  And what other things
> define Py_TPFLAGS_HEAPTYPE?

There is no way to distinguish a new-style class, because all type
objects can be considered new-style classes.  The only thing you could
do is checking for "not classic-class".

The HEAPTYPE flag is set only for new-style classes that are created
dynamically; but eventually I expect that the built-in exceptions will
be statically declared new-style classes.

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