[PyQt] Empty and template classes

Phil Thompson phil at riverbankcomputing.com
Sun Apr 10 16:40:50 BST 2016


On 10 Apr 2016, at 2:53 pm, Shaheed Haque <srhaque at theiet.org> wrote:
> 
> Hi Phil,
> 
> On 10 April 2016 at 13:32, Phil Thompson <phil at riverbankcomputing.com> wrote:
>> On 10 Apr 2016, at 1:21 pm, Shaheed Haque <srhaque at theiet.org> wrote:
>>> 
>>> Hi,
>>> 
>>> One enhancement request, and a question. First, SIP 4.16.9 does not
>>> like empty classes like this:
>>> 
>>> class KUserOrGroupId
>>> {
>>> };
>>> 
>>> The above results in a syntax error. Adding anything makes it work, for example:
>>> 
>>> class KUserOrGroupId
>>> {
>>> %TypeHeaderCode
>>> #include <KCoreAddons/kuser.h>
>>> %End
>>> };
>>> 
>>> is accepted. It would be nice to have support for this corner case.
>>> Second, the syntax for template classes does not seem to work as I
>>> expected. This example results in a syntax error, as does every
>>> variation I could think of (including trying to match PyQt):
>>> 
>>> template <typename T>
>>> class KUserOrGroupId<T>
>>> {
>>> %TypeHeaderCode
>>> #include <KCoreAddons/kuser.h>
>>> %End
>>> };
>>> 
>>> Like the function case, I realise the implementation for this is not
>>> trivial (templated methods and the like), but I cannot seem to make
>>> the basic syntax work. It should, right?
>> 
>> See...
>> 
>> http://pyqt.sourceforge.net/Docs/sip4/specification_files.html#syntax-definition
>> 
>> ...also look at the PyQt .sip files.
>> 
>> In this case, omit 'typename'.
> 
> I tried (having reviewed the syntax page and parser.y) several
> variations such as this:
> 
> ====
> %Module test_template
> 
> template <T>
> class KUserOrGroupId<T>  <<< line 4
> {
> %TypeHeaderCode
> #include <KCoreAddons/kuser.h>
> %End
> };
> ====
> 
> which does not work. However, it *does* work if I discard the "<T>"
> from line 4, or use %MappedType. What is eluding me are the rules I
> need to follow for references to T within the class. For example,
> let's say the class contained a method with the signature:
> 
>    void foo(T *bar);
> 
> If I understand correctly, the semantics of passing T in are knowable,
> but SIP does not like the "T", and I have not been able to work out
> how the signature for foo should be written to get it past the syntax
> errors. Is a template class able to support things like this (once I
> implement the %MappedType)?

I honestly can't remember if it's supposed to work or not. What's the error when SIP 'does not like the "T"'?

I would actually approach it from the other end - first of all how do you want to represent KUserOrGroupId in Python?

Phil


More information about the PyQt mailing list