[PyQt] sip: Problem with inheritance and function overloads

Phil Thompson phil at riverbankcomputing.com
Sun Jul 25 12:10:48 BST 2010


On Fri, 23 Jul 2010 10:53:37 +0200, Daniel Stöckel
<dstoeckel at bioinf.uni-sb.de> wrote:
> Hi,
> 
> I seem to have noticed a bug in sip concerning function overloads that
> occur 
> because of inheritance:
> 
> I have a C++ project in which I have classes like this (I used this
actual
> toy 
> example to reproduce the problem):
> 
>   class A
>   {
>       public:
>           void do_sth(DummyA&);
>   };
> 
>   class B : public A
>   {
>       public:
>           void do_sth(DummyB&);
>   };
> 
> The sip wrapper code is also straight forward:
> 
>   class A
>   {
>   %TypeHeaderCode
>       #include "bla.h"
>   %End
>       public:
>           void do_sth(DummyA&);
>   };
> 
>   class B : A 
>   {
>   %TypeHeaderCode
>       #include "bla.h"
>   %End
>       public:
>           void do_sth(DummyB&);
>   };
> 
> In C++ it is now possible to call do_sth on class B with both: DummyA
and 
> DummyB due to function overloading.

No you can't. You can only do that if both implementations of do_sth() are
in the same class. Otherwise there would be no reason for C++'s "using"
directive when applied to methods.

> In the generated sip wrapper however 
> calling do_sth on an object of type B with an object of type DummyA
causes
> the 
> following error:
> 	"TypeError: B.do_sth(): argument 1 has unexpected type 'DummyA'"
> Note that regular overloading, so if both do_sth() methods were defined
> and 
> wrapped in class B, works just fine. It seems to me as if sip does not 
> propagate information about function overloads down the inheritance
tree.
> 
> Am I doing something wrong or is this indeed a bug/limitation in sip?
> 
> Greetings,
> Daniel

Phil


More information about the PyQt mailing list