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

Alex Martelli aleax at aleax.it
Sun Jan 16 10:47:34 CET 2005


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

> Phillip J. Eby wrote:
>> Couldn't we require new-style exceptions to inherit from Exception?  
>> Since there are no new-style exceptions that work now, this can't 
>> break existing code.
>
> This would require to make Exception a new-style class, right?

Not necessarily, since Python supports multiple inheritance:

class MyException(Exception, object): .....

there -- a newstyle exception class inheriting from oldstyle Exception. 
  (ClassType goes to quite some trouble to allow this, getting the 
metaclass from _following_ bases if any).

Without inheritance you might similarly say:

class AnotherOne(Exception):
     __metaclass__ = type
     ...

> This, in itself, could break existing code.

Not necessarily, see my previous post.  But anyway, PJE's proposal is 
less invasive than making Exception itself newstyle.


Alex



More information about the Python-Dev mailing list