Skip to content

Commit 8392c93

Browse files
committed
Monkey patch __nonzero__ onto QPyNullVariant for easier null check.
Who doesn't love monkeys :)
1 parent 3115c30 commit 8392c93

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

python/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@
2222
__copyright__ = '(C) 2007, Martin Dobias'
2323
# This will get replaced with a git SHA1 when you do a git archive
2424
__revision__ = '$Format:%H$'
25+
26+
from PyQt4.QtCore import QPyNullVariant
27+
from types import MethodType
28+
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
35+
36+
QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)

0 commit comments

Comments
 (0)