don't understand MRO

Terry Reedy tjreedy at udel.edu
Thu Jun 23 13:22:58 EDT 2005


"Uwe Mayer" <merkosh at hadiko.de> wrote in message 
news:d9eluf$ojc$1 at news2.rz.uni-karlsruhe.de...
> I have a subclassed PyQt class:
>
> class Node(object):
>        def move(self, x,y): pass
>
> class CRhomb(QCanvasPolygon, Node): pass
>
> $ python
> v2.4.1
>>>> CRhomb.mro()
> [<class '__main__.CRhomb'>, <class 'qtcanvas.QCanvasPolygon'>, <class
> 'qtcanvas.QCanvasPolygonalItem'>, <class 'qtcanvas.QCanvasItem'>, <class
> 'qt.Qt'>, <type 'sip.wrapper'>, <class '__main__.Node'>, <type 'object'>]

For those who don't know, 'mro' stands for 'method resolution order'.  The 
method returns a list of classes (all except the first are base or super 
classes of the first) in the order in which their dictionaries are searched 
for method (or other attribute) names.

>
>>>> a = CRhomb()
>>>> a.move(1,2)
>
> This executes also Node.move(a, 1,2)
> Why?

In the absence of other information, I would presume that none of the other 
classes have a move() method.

> Because even QCanvasItem.move delegates the call to the derived object? 
> But
> qt.Qt does not have a move() method... how does it get passed on to Node?

Are you sure that QCanvasItem has a move method?  What results from
>>> print qtcanvas.QCanvasItem.move # ?
If so, I would need to see its code to try to answer.

Terry J. Reedy






More information about the Python-list mailing list