[PyQt] QPyNullVariant and bool()

Phil Thompson phil at riverbankcomputing.com
Wed Apr 25 08:26:22 BST 2012


On Tue, 24 Apr 2012 14:28:02 -0400, Deniz Turgut <dturgut at gmail.com>
wrote:
> Would it be logical to add a __nonzero__ method to QPyNullVariant
> which always returns False?
> 
> I was going through a code of mine which broke with a new version of
> PyQt. I realized that it was because there is no __nonzero__ method in
> QPyNullVariant so bool(QPyNullVariant) is always True.
> 
> Right now, if you use QVariant api 2, you can't check nicely (without
> typechecking) whether you get a nonzero value or Null/Falsy value.

>From a purist point of view I don't associate Null with False (or with
True either but the current behaviour reflects the Python default).

>From a portability point of view it's a change in the API.

>From a pragmatic point of view I need to be persuaded - I've not been
affected by the issue myself.

Phil


More information about the PyQt mailing list