[Python-Dev] a bit confused about the new type/class stuff (original) (raw)
Skip Montanaro skip@pobox.com (Skip Montanaro)
Wed, 3 Oct 2001 14🔞05 -0500
- Previous message: [Python-Dev] dummy __del__ in SocketServer.BaseRequestHandler
- Next message: [Python-Dev] Re: [pygtk] a bit confused about the new type/class stuff
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
- Previous message: [Python-Dev] dummy __del__ in SocketServer.BaseRequestHandler
- Next message: [Python-Dev] Re: [pygtk] a bit confused about the new type/class stuff
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]