[Python-Dev] Exceptions *must*? be old-style classes?

Alex Martelli aleax at aleax.it
Sun Jan 16 10:44:14 CET 2005


On 2005 Jan 16, at 10:27, Martin v. Löwis wrote:

> Simon Percivall wrote:
>> What would happen if Exception were made a new-style class, enforce
>> inheritance from Exception for all new-style exceptions, and allow all
>> old-style exceptions as before.
>
> string exceptions would break.

Couldn't we just specialcase strings specifically, to keep 
grandfathering them in?

> In addition, code may break which assumes that exceptions are classic
> instances, e.g. that they are picklable, have an __dict__, and so on.

There would be no problem giving the new
class Extension(object): ...
a __dict__ and the ability to get pickled, particularly since both come 
by default.

The "and so on" would presumably refer to whether special methods 
should be looked up on the instance or the type.  But as I understand 
the question (raised in the threads about copy.py) the planned solution 
is to make special methods their own kind of descriptors, so even that 
exoteric issue could well be finessed.

> > Am I wrong in assuming that only the
>> most esoteric exceptions inheriting from Exception would break by
>> Exception becoming new-style?
>
> Yes, I think so.

It seems to me that if the new-style Exception is made very normally 
and strings are grandfathered in, we ARE down to exoteric breakage 
cases (potentially fixable by those new magic descriptors as above for 
specialmethods).


Alex



More information about the Python-Dev mailing list