From 326d707717104c19a588ecb2fd6c3e7a0579dc05 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 7 Nov 2017 15:42:25 -0800 Subject: [PATCH] Fix comparing DataViewItem with None --- etg/dataview.py | 6 ++++-- unittests/test_dataview.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/etg/dataview.py b/etg/dataview.py index 0ef7b34c..0c1e98e2 100644 --- a/etg/dataview.py +++ b/etg/dataview.py @@ -84,8 +84,10 @@ def run(): c.addCppMethod('long', '__hash__', '()', """\ return (long)self->GetID(); """) - c.addCppMethod('bool', '__eq__', '(wxDataViewItem* other)', "return (self->GetID() == other->GetID());") - c.addCppMethod('bool', '__ne__', '(wxDataViewItem* other)', "return (self->GetID() != other->GetID());") + c.addCppMethod('bool', '__eq__', '(wxDataViewItem* other)', + "return other ? (self->GetID() == other->GetID()) : false;") + c.addCppMethod('bool', '__ne__', '(wxDataViewItem* other)', + "return other ? (self->GetID() != other->GetID()) : true;") c.addAutoProperties() diff --git a/unittests/test_dataview.py b/unittests/test_dataview.py index 375989a8..2d373cae 100644 --- a/unittests/test_dataview.py +++ b/unittests/test_dataview.py @@ -54,6 +54,11 @@ class dataview_Tests(wtc.WidgetTestCase): self.assertTrue(int(dvi.GetID()) == n) + def test_dataviewItem8(self): + dvi = dv.DataViewItem(111) + assert (None == dvi) == False + assert (None != dvi) == True + #------------------------------------------------------- def test_dataviewItemAttr1(self):