From 0fd5fd137f5e8b99bdeb52b5dd91dcb87611dfca Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Wed, 12 Jun 2013 08:42:01 +1000 Subject: [PATCH] Don't patch QPyNullVariant if it doesn't exist --- python/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 0940ed13a684..59d4d1479cd8 100755 --- a/python/__init__.py +++ b/python/__init__.py @@ -23,14 +23,17 @@ # 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 +try: + # Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier. + # >>> value = QPyNullVariant("int") + # >>> if value: + # >>> print "Not a null value" + from types import MethodType + from PyQt4.QtCore import QPyNullVariant + def __nonzero__(self): + return False -# 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) +except ImportError: + pass -QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)