[PyQt] How are template methods supposed to work?

Shaheed Haque srhaque at theiet.org
Sat Apr 9 17:30:01 BST 2016


Phil,

On 9 April 2016 at 17:23, Phil Thompson <phil at riverbankcomputing.com> wrote:
> On 9 Apr 2016, at 5:01 pm, Shaheed Haque <srhaque at theiet.org> wrote:
>>
>> Hi,
>>
>> I'm having some trouble trying to wrap KDE's KF5 libraries in the area
>> of template support using SIP 4.16.9. For example, the following test
>> case results in a syntax error:
>>
>> ======
>> %Module test_template
>>
>> class MyClass
>> {
>> public:
>>    template <typename T>  // line 6
>>    int mymethod();
>> };
>> ======
>>
>> $ sip test_template.sip
>> sip: test_template.sip:6: syntax error
>>
>>
>> I've poked around PyQt4, PyQt5 and PyKDE4, and though I see a
>> scattering of templated classes, I don't see any templated methods.
>> The docs (and the parser.y, if I am reading it right) do suggest that
>> this should work. What am I missing? Does SIP really support templates
>> generally?
>
> No.
>
>> Now I confess to being a little unclear what the Pythonic
>> representation of such a thing might be, and if SIP does not support
>> this, any suggestions on how to approach this kind of problem would be
>> welcome.
>
> You have to provide some sort of handwritten implementation. What that looks like depends on the particular case. The first thing to consider is what values of T need to be supported. Is T always going to be a fundamental type, or a class, or both. In any case you are probably going to have to decide on a fixed subset of possible values of T to support.


That's pretty much what I was beginning to think. Thanks a lot for the
quick reply!

Shaheed

>
> Phil


More information about the PyQt mailing list