I'm having trouble with the use of polymorphism in object oriented programming in python. Here I define a specialisation of the list class that overrides the append and setitem methods
class MyList(list):
def __setitem__(self, key,value):
super(MyList,self).__setitem__(key,value)
print("bubu")
def append(self,value):
super(MyList,self).append(value)
print("bibi")
Now if I test this class with
myobj = MyList()
myobj.append(1)
myobj[0]=3
I get "bibi", and then "bubu", as expected. But if I use a MyList object with an external module
import heapq
myobj = MyList()
heapq.heappush(myobj,1)
The function heappush from heapq is supposed to call myobj.append (I checked the sources https://github.com/python/cpython/blob/3.10/Lib/heapq.py). But I get no "bibi" this time ! Isn't the "append" called supposed to be that of the instance passed in arguments ?
Where are my bibis ?? :)