A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-October/017732.html below:

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

[Python-Dev] a bit confused about the new type/class stuffSkip Montanaro skip@pobox.com (Skip Montanaro)
Wed, 3 Oct 2001 14:18:05 -0500
I have a class hierarchy I'm trying to migrate to 2.2 using the latest stuff
from CVS on both the Gtk and Python sides of the fence.  Conceptually its
skeleton looks like

    class Object:
        ...

    class Widget(Object):
        ...

    class Button(Widget):
        ...

(It's a bunch of wrappers around Gtk widgets.  The wrappers happen to use
delegation instead of instantiation, so my Button class is not subclassed
from gtk.Button.  In particular, it's *not* one of the new subclassable
types.)

At one point in my code I test to see if one of my Button instances is in a
list of Widget instances and I get a TypeError:

    TypeError: Button.__cmp__(x,y) requires y to be a 'Button', not a 'instance'

If I test for b's inclusion in l, even if I draw b from l:

    >>> 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'

I get an error.

I don't define a __cmp__ method for the Button class or any of its
ancestors, but if I print b.__cmp__ something is definitely there:

    >>> b.__cmp__
    <method-wrapper object at 0x83aae78>

This was all working using Python 2.1.  I haven't changed anything so far in
my code other than to adapt to the new PyGtk naming scheme (e.g., gtk.Button
vs. gtk.GtkButton) and recompile/install Gtk, PyGtk, Python and friends.  In
particular, I believe I have a hierarchy of so-called "classic" classes.

I'm going to toddle off an reread the various PEPs, but would appreciate an
insight or two on where this error is coming from.

Thx,

-- 
Skip Montanaro (skip@pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4