[PyKDE] Bug with super and QObject
Phil Thompson
phil at riverbankcomputing.co.uk
Sun Apr 17 08:47:29 BST 2005
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
More information about the PyQt
mailing list