From 8392c93d8e6de82ff12330af1b79b8437e76ec0f Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Tue, 11 Jun 2013 22:13:34 +1000 Subject: [PATCH] Monkey patch __nonzero__ onto QPyNullVariant for easier null check. Who doesn't love monkeys :) --- python/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 2f38bae0d71..0940ed13a68 100755 --- a/python/__init__.py +++ b/python/__init__.py @@ -22,3 +22,15 @@ __date__ = 'January 2007' __copyright__ = '(C) 2007, Martin Dobias' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' + +from PyQt4.QtCore import QPyNullVariant +from types import MethodType + +# Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier. +# >>> value = QPyNullVariant("int") +# >>> if value: +# >>> print "Not a null value" +def __nonzero__(self): + return False + +QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)