[PyQt] PyQt5 NULL QVariant

Matthias Kuhn matthias at opengis.ch
Fri Apr 22 10:22:45 BST 2016


Hi Phil

On 04/22/2016 10:52 AM, Phil Thompson wrote:
> On 22 Apr 2016, at 6:52 am, Matthias Kuhn <matthias at opengis.ch> wrote:
>> On 04/21/2016 05:59 PM, Phil Thompson wrote:
>>>> Which I think are properly addressed by introducing the
>>>> sip.enableautoconversion() function to allow turning autoconversion off.
>>>> But I struggle to see why this requires breaking compatiblity with SIP
>>>> API V2 if autoconversion is turned on.
>>> Maybe I'm not understanding. Apart from QPyNullVariant not being implemented (which was a hack), what has broken?
>> If there is a QVariantList with [ 1, QVariant( QVariant::Int ), 0 ] it's
>> converted to a python list [1, 0, 0] and hence the semantic of NULL
>> values is lost. This is probably caused by the lack of QPyNullVariant
>> but it breaks compatibility with sip api v2 code. I don't think a
>> non-hacky replacement for QPyNullVariant has been introduced (apart from
>> disabling autoconversion) or am I missing something?
> No you're not. I can see that the loss of QPyNullVariant can be inconvenient when dealing with C++ code that makes significant use of Null QVariants. However adding it back would itself be a break in compatibility. I'm happy to consider that but it wouldn't be until PyQt v5.7 at the earliest - unless you can think of another solution?

I'd appreciate anything that can be made "compatible enough", be it
reintroducing PyQtNullVariant or a QVariant( QVariant::Type ) style
value for NULL.

Another solution would be introducing yet another method along the lines
of sip.enableautoconversion() like sip.enablenullvariant(). That would
not break compatibility within the PyQt5 series.

Short version, from a ducktyping perspective, if it returns True on
isNull() it will work for us.
Longer version, we monkey patched the __eq__ and some other methods of
PyQtNullVariant (a hack on top of a hack ;) ) so we can do that as well
with anything as long as it's an object and the information
null/valid/invalid is present.

Waiting for 5.7 works for us, we're still shipping PyQt4 based code for
the next couple of months.

Matthias


More information about the PyQt mailing list