Skip to content

Commit 0fd5fd1

Browse files
committed
Don't patch QPyNullVariant if it doesn't exist
1 parent 052669f commit 0fd5fd1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

python/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
# This will get replaced with a git SHA1 when you do a git archive
2424
__revision__ = '$Format:%H$'
2525

26-
from PyQt4.QtCore import QPyNullVariant
27-
from types import MethodType
26+
try:
27+
# Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier.
28+
# >>> value = QPyNullVariant("int")
29+
# >>> if value:
30+
# >>> print "Not a null value"
31+
from types import MethodType
32+
from PyQt4.QtCore import QPyNullVariant
33+
def __nonzero__(self):
34+
return False
2835

29-
# Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier.
30-
# >>> value = QPyNullVariant("int")
31-
# >>> if value:
32-
# >>> print "Not a null value"
33-
def __nonzero__(self):
34-
return False
36+
QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)
37+
except ImportError:
38+
pass
3539

36-
QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)

0 commit comments

Comments
 (0)