From dcd17fdf8ff64dd809e8227368ccc86f137072ad Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Thu, 29 Aug 2013 12:17:20 +0200 Subject: [PATCH] QPyNullVariant() equals to QPyNullVariant(), qgis.core.NULL >>>> from qgis.core import NULL >>>> lyr.getFeatures().next().attributes()[0] == NULL True --- python/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 1fe8e96ce092..cc8179b01f07 100755 --- a/python/__init__.py +++ b/python/__init__.py @@ -46,7 +46,17 @@ def __nonzero__(self): def __repr__(self): return 'NULL' + def __eq__(self, other): + return isinstance(other, QPyNullVariant) or other is None + QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant) QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant) + QPyNullVariant.__eq__= MethodType(__eq__, None, QPyNullVariant) + + # define a dummy QPyNullVariant instance NULL in qgis.core + # this is mainly used to compare against + # so one can write if feat['attr'] == NULL: + from qgis import core + core.NULL = QPyNullVariant( int ) except ImportError: pass