Reputation: 20856
I have created 2 classes A & B, B inherits A. I'm using the isinstance to check if b is of type a and it returns false. Shouldn't be true?
class a():pass
class b(a):pass
print isinstance(b,a)
Upvotes: 3
Views: 1453
Reputation: 48
b is class, not object, so it is not instance of any class. To get True, call isinstance(b(),a)
Upvotes: 1
Reputation: 798536
No. b
is an instance of either type
or classobj
, not of a
. You may want the issubclass
function instead.
>>> issubclass(b, a)
True
Upvotes: 7