"my brain hurts" or is isinstance broken?
Robert Kuzelj
robert_kuzelj at yahoo.com
Tue Jul 2 18:06:17 EDT 2002
hi,
after playing around with all this metastuff it seems
that isinstance is broken (but after all it could also be,
that my brain finally broke down).
here some script that checks for the instancetype of various
objects defined within that script.
>>>typestest.py
import types
import string
class metatype(type): pass
class A1: pass
class B1(object): pass
class C1: __metaclass__ = metatype
values = [ [A1, A1()],
[B1, B1()],
[C1, C1()]]
def getInstanceInfos(row):
return [row[0].__name__,
str(isinstance(row[0], types.InstanceType)),
str(isinstance(row[0], types.ClassType)),
str(isinstance(row[0], types.TypeType)),
str(isinstance(row[1], types.InstanceType)),
str(isinstance(row[1], types.ClassType)),
str(isinstance(row[1], types.TypeType))]
print
print "INSTANCEINFOS"
print " name | inst | class | type | inst | class | type "
print "-----------------------------------------------------"
for row in values:
print " " + string.join(getInstanceInfos(row), " | ")
>>>typestest.py #end
>>>output
INSTANCEINFOS
name | inst | class | type | inst | class | type
-----------------------------------------------------
A1 | 0 | 1 | 0 | 1 | 0 | 0
B1 | 0 | 0 | 1 | 0 | 0 | 0
C1 | 0 | 0 | 1 | 0 | 0 | 0
>>>output
my question is why are the B1() and C1() not types.InstanceType?
and if this is not a bug - of what type are B1() and C1()?
ciao robertj
More information about the Python-list
mailing list