[Python-bugs-list] [ python-Bugs-751321 ] Classes inheritig from object are not class type.

SourceForge.net noreply@sourceforge.net
Tue, 10 Jun 2003 22:29:44 -0700


Bugs item #751321, was opened at 2003-06-09 15:33
Message generated for change (Comment added) made by e078120
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=751321&group_id=5470

Category: Extension Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Roger Wenham (e078120)
Assigned to: Nobody/Anonymous (nobody)
Summary: Classes inheritig from object are not class type. 

Initial Comment:
Isinstance(<classinstance>, types.ClassType) will
return false if the class inherits from object.

Here is a demo:

import types
 
class a:
        def test(self):
                pass
 
class b(object):
        def test(self):
                pass
  
if __name__ == '__main__':
        if isinstance(a, types.ClassType):
                print "a is a class"
        else:
                print "a is not a class"
 
        if isinstance(b, types.ClassType):
                print "b is a class"
        else:
                print "b is not a class"

The output look like this:


roger@linux_lap:~ > python demo.py
a is a class
b is not a class



----------------------------------------------------------------------

>Comment By: Roger Wenham (e078120)
Date: 2003-06-11 07:29

Message:
Logged In: YES 
user_id=240941

Maybe I'm missing something, but to me a class is a class
and should allways be a ClassType. For instance if I have
pickled
some objects, when unpickling, how else can I identify that
it was a class that I pickled, and that I can take an
instance of it?

With the old style classes, a class was class type and if i
take an instance, it's type is instance, logical.

With new style classes, an class is type 'type', and an
instance of it is type class.

Is it not logical that a class is a class and an istance is
an instance?  

 





----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-10 20:07

Message:
Logged In: YES 
user_id=89016

The reason for this is that new style classes have a
different meta class than classic classes. This is
documented in http://www.python.org/2.2.3/descrintro.html:
"""The built-in 'type' is the most common metaclass; it is
the metaclass of all built-in types. Classic classes use a
different metaclass: the type known as types.ClassType."""

Why do you think this is a bug?


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=751321&group_id=5470