isinstance is broken

Michael Hudson mwh at python.net
Mon Jan 20 05:50:47 EST 2003


mis6 at pitt.edu (Michele Simionato) writes:

> Michael Hudson <mwh at python.net> wrote in message news:<7h3n0lyl3pf.fsf at pc150.maths.bris.ac.uk>...
> > However:
> > 
> > ->> type(c).__new__
> > <built-in method __new__ of type object at 0x80f2380>
> > 
> > Objects/classobject.c:instance_getattr looks in c.__class__.
> > 
> > This function isn't much use, it seems.
> 
> Here I don't feel stupid; I didn't know that. You are saying essentially
> that c *does* inherit __new__ from object, but it cannot be accessed with
> c.__new__ due to an implementation detail (i.e. getattr looks for __class__
> which is not there);

Well, c.__class__ is there, it's just different from type(c).

> it can be accessed via type(c) anyway.  This is an inconsistency of
> old style classes: they inherits from object but you cannot access
> object methods in the usual way.

It has to be said, writing the post you were replying to made me
realise just how icky old-style objects are!

Cheers,
M.

-- 
    -Dr. Olin Shivers,
     Ph.D., Cranberry-Melon School of Cucumber Science
                                           -- seen in comp.lang.scheme




More information about the Python-list mailing list