[PyQt] SIP feature request (__rmul__)

Phil Thompson phil at riverbankcomputing.com
Sat Feb 2 12:33:26 GMT 2008


On Friday 01 February 2008, Phil Thompson wrote:
> On Thursday 31 January 2008, Jim Crowell wrote:
> > With __rmul__ not being in the list of supported special methods, is
> > there any way I can implement Float*MyVectorClassInstance? If not, any
> > chance of getting __rmul__ added?
>
> That turned out to be easier than expected. Support for __radd__, __rsub__,
> __rmul__, __rdiv__, __rmod__, __rlshift__, __rrshift__, __rand__, __ror__,
> and __rxor__ will be in tonight's snapshot.

I've had second thoughts about this.  The reflected methods don't have C++ 
equivalents so it's not obvious what they should do - and you don't need them 
anyway.

I don't know if Float is a real class, or you mean the C++ float or double. 
I'll assume the latter.

I assume that the C++ library has...

    MyVectorClass MyVectorClass::operator*(double);

If the C++ library supports the reflected version then I assume it also has...

    MyVectorClass operator*(double, const MyVectorClass &);

...in which case you just wrap it as normal.

If the C++ library doesn't support the reflected version, but you want the 
Python module to do so then add the global operator and provide %Method 
code...

    MyVectorClass operator*(double, const MyVectorClass &);
    %MethodCode
        sipRes = new MyVectorClass(*a1 * a0);
    %End

Phil


More information about the PyQt mailing list