Skip,

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

Delegating magic methods to another instance rarely is a good idea.
Instead of writing a __cmp__, why not fix the wrong `__getattr__`
method? Otherwise you'll run into troubles again. Some things
immediately come to mind:

- Did you redefine __hash__, too? If not, putting your classes into a
  dictionary might lead to nasty surprises.

- Someday, James defines a __eq__ method for GObject, and you start
  all over again...

- Python grows some additional magic and code that used to work
  suddenly breaks with bizarre messages...

I've come to the conclusion that most __getattr__ implementations
delegating to other objects should start with:

        if name.startswith ("__") and name.endswith ("__") :
            raise AttributeError, name

If you want to delegate magic methods, list the names to be delegated
explicitly.

Christian

PS: I'd hope that you take another look at the `__getattr__`
    implementation I proposed 6 weeks ago.

-- 
Christian Tanzer                                         [EMAIL PROTECTED]
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to