[PyKDE] Re: Method wrappers not shared

Phil Thompson phil at riverbankcomputing.co.uk
Fri Oct 28 18:16:33 BST 2005


On Friday 28 October 2005 3:05 pm, Giovanni Bajo wrote:
> Phil:
> >>> import qt
> >>> a = qt.QWidget.acceptDrops
> >>> b = qt.QWidget.acceptDrops
> >>> a is b
>
> False
>
> >>> id(a), id(b)
>
> (9674384, 9670704)
>
> >>> id(qt.QWidget.acceptDrops)
>
> 9831568
>
> >>> id(qt.QWidget.acceptDrops)
>
> 9831568
>
> It looks like these method wrappers are recreated each time I need them (I
> believe it has to do with the lazy binding construction, right)? Would it
> be possible to change SIP so that it preserves existing methods and reuses
> them, or is it too much work?

It is lazy binding related. The normal getattro method is used first (in case 
the user as manually patched in a method). If the lazy lookup saved the 
result in the type dictionary, and it was also reimplemented in a sub-type 
then the super-type version would always be found in preference to the 
sub-type version in subsequent lookups.

One option would be to maintain a separate dictionary of cached lazy lookups 
and treat then as candidate results to be used if no better result was found 
further down the class hierachy. Needs more thought.

> This would be needed for tools like epydoc. Basically, given an object like
> qt.QWidget.acceptDrops, epydoc has no way to find it looking within the
> module qt, nor it has a way to understand through inspection that
> qt.QWidget.acceptDrops come from qt.pyd (the __module__ attribute contains
> None, and __objclass__ does not exist).
>
> I know this is really a minor issue, but I would like to get it fixed.
> Basically, epydoc can't be used altogether on PyQt applications because it
> wastes too much time looking for thousands of duplicates of each and every
> method of each and every qt class, in each and every module which does
> "from qt import *". Ewww.
>
> Another fix which would be good for me would be to have the __module__
> attribute defined for methods. Probably easier to implement than reusing
> method objects?

You mean this is another way to solve the same problem? Or it's a different 
problem?

I'll add to the TODO list.

Phil




More information about the PyQt mailing list