[pygtk] Re: [Python-Dev] a bit confused about the new type/class stuff

Skip Montanaro skip@pobox.com (Skip Montanaro)
Thu, 4 Oct 2001 08:41:48 -0500


    >> >>> l
    >> [<Button object (GtkButton) at 0x8293134>, <Button object (GtkButton) at 0x8296ac4>, <Button object (GtkButton) at 0x8397fb4>]
    >> >>> b = l[0]
    >> >>> b in l
    >> Traceback (most recent call last):
    >>   File "<stdin>", line 1, in ?
    >> TypeError: Button.__cmp__(x,y) requires y to be a 'Button', not a 'instance'

A brief conversation with Guido cleared up what was happening.  In my class
hierarchy I didn't implement __cmp__, but I did implement __getattr__, which
was delegating most things to the underlying Gtk widget, so 

    b.__cmp__(l)

became

    b._real_widget.__cmp(l)

which then barfed.

Writing a __cmp__ method that does the right thing cleared up the problem.

Skip