I just noticed that
isinstance(myob, MyClass)
does not only return True
when myob
is an instance of MyClass
but also if myob
is an instance of a class that inherits from MyClass
.
To be more clear, consider the following:
class Book(object):
def __init__(self, cover)
self._cover = cover
class Novel(Book):
def __init__(self, cover, category):
Book.__init__(self, cover)
self._category = category
When instanciating Novel as follows:
novel = Novel('hardcover', 'police')
then
print(isinstance(novel, Book))
and
print (isinstance(novel , Novel))
both print True
.
Why is that so? In my sense, novel
is a Novel
instance, not a Book
one...
Also, relevant to this :
In order to get the "grand-mother" (sic) class, I do:
print(novel.__class__.__bases__)
Is there a more direct way?