[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Bug with super and QObject
From:       Phil Thompson <phil () riverbankcomputing ! co ! uk>
Date:       2005-04-17 7:47:29
Message-ID: 200504170847.29070.phil () riverbankcomputing ! co ! uk
[Download RAW message or body]

On Tuesday 12 April 2005 4:19 pm, Giovanni Bajo wrote:
> Hello:
> >>> from qt import *
> >>> class A(QObject):
>
> ...     pass
> ...
>
> >>> a=A()
> >>> super(A, a).emit("foo")
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'super' object has no attribute 'emit'
>
> >>> super(A, a).emit(PYSIGNAL("foo"), ())
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'super' object has no attribute 'emit'
>
> Why is super broken?

This is more complicated than I first thought. For reasons that I don't fully 
understand, super implements type attribute lookup by searching the type 
dictionary (and that of any super-types) explicitly. It does not use the 
usual method of attribute lookup and so bypasses the tp_getattro hook used by 
PyQt.

I haven't managed to think of a way wround the problem - either by using the 
Python API, or by being sneaky.

It's difficult to argue that this is a Python bug as the documentation doesn't 
say much about the nature and behaviour of the object returned by super. 
However, given it's intended use, you would expect it's behaviour to be 
compatible with normal type attribute lookup. After all, what PyQt is doing 
here is perfectly legitimate and uses the documented API.

Apparently there have been thoughts about providing an extra lookup hook which 
I believe would solve the problem - whether this will be implemented remains 
to be seen.

In the meantime, all I think I can do is document that super is broken for 
types generated by SIP. The only work around is to make sure that the 
attribute has already been referenced (and so has been cached in the type 
dictionary) before calling super.

Phil

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic