[PyQt] Calling protected methods on objects

Phil Thompson phil at riverbankcomputing.com
Mon Sep 1 22:35:31 BST 2008

On Mon, 01 Sep 2008 22:29:37 +0200, Simon Edwards <simon at simonzone.com>
> Hello Phil,
> I'm busy working on integrating Python with Plasma in KDE 4. The API for 
> doing network distributed applets is a bit convoluted, there is a lot of 
> delegation of methods calls to other objects. I've hit a part where it 
> would be really handy if I could call protected methods on objects which 
> were not created by Python itself. SIP appears to explicitly prevent 
> this kind of access, although I've commented out the check in 
> getComplexCppPtr() and it appears to work fine.
> * Is there a technical reason why this is forbidden? or is it more 
> philosophical?
> * I would like an official way in SIP to call protected 
> methods/functions regardless of where the object came from. Perhaps, 
> just a way to "unlock" an instance making all of its method available. 
> Is this possible?


I'm surprised that it works by just disabling the check as the result is
that you are calling a sub-classes's method. However that method only ever
calls the original protected method and so it is probably safe - highly
illegal, but safe. The same is probably true of protected virtual methods.

The other thing that would worry me is portability.

I need to think this over for a bit to feel comfortable with it.


More information about the PyQt mailing list