[PyKDE] __unicode__ unsupported by sip?

Phil Thompson phil at riverbankcomputing.co.uk
Thu Mar 16 20:05:09 GMT 2006


On Thursday 16 March 2006 7:16 pm, Nigel Stewart wrote:
> Hello all,
>
> In our mixed C++/python environment we want to interchange strings
> between C++ and python as either QString or python unicode strings.
> We have some sip bindings providing __str__ conversion to python
> strings, but when we converted these to __unicode__ methods producing
> python unicode strings, things mysteriously stopped working.
>
> It appears that sip doesn't generate any C++ code for __unicode__
> methods, wheras it does for __str__ methods.  Grepping sipgen
> for the 20060315 sip snapshot seems to confirm this.  (see attachment)
>
> Is it reasonable for the MethodCode of a __str__ method to produce
> a unicode string, or is it sipgen that needs attention?

__str__ can return a Unicode object.

> There is one __unicode__ method in PyQt, for QString.
> PyQt also provides QString::__str__, also returning a
> unicode string.
>
> So, why does sip accept __unicode__ if it is ignored?

So that .sip files will build with SIP v3 (which needs __unicode__ for 
supporting older versions of Python) and with SIP v4 (which doesn't).

The bug is that the SIP docs mentions __unicode__ at all.

Phil




More information about the PyQt mailing list