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

Guido van Rossum gvanrossum at gmail.com
Mon Jan 17 19:44:54 CET 2005


> >That would be much more reasonable if Exception itself was a new-style
> >class. As long as it isn't, you'd have to declare new-style classes
> >like this:
> >
> >class MyError(Exception, object):
> >     ...
> >
> >which is ugly.
> 
> I was thinking the use case was that you were having to add 'Exception',
> not that you were adding 'object'.  The two times in the past that I wanted
> to make a new-style class an exception, I *first* made it a new-style
> class, and *then* tried to make it an exception.  I believe the OP on this
> thread described the same thing.
> 
> But whatever; as long as it's *possible*, I don't care much how it's done,
> and I can't think of anything in my code that would break from making
> Exception new-style.

Well, right now you would only want to make an exception a new style
class if you had a very specific use case for wanting the new style
class. But once we allow new-style exceptions *and* require them to
inherit from Exception, we pretty much send the message "if you're not
using new-style exceptions derived from Exception your code is out of
date" and that means it should be as simple as possible to make code
conform. And that means IMO making Exception a new style class.

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


More information about the Python-Dev mailing list