From f0c0dab5a9a463f87ca723cd4a4d6241311e0a0e Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 11 Nov 2014 20:11:32 +0000 Subject: [PATCH] python: Implement equality checks for EnumValue derived classes. Fixes bug #443. --- bindings/python/sigrok/core/classes.i | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 066dbf82..b05f21e1 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -382,6 +382,22 @@ std::map dict_to_map_options(PyObject *dict, %enddef %define %enumextras(Class) +%extend sigrok::Class +{ + long __hash__() + { + return (long) $self; + } + +%pythoncode +{ + def __eq__(self, other): + return (type(self) is type(other) and hash(self) == hash(other)) + + def __ne__(self, other): + return (type(self) is not type(other) or hash(self) != hash(other)) +} +} %enddef %include "../../../swig/classes.i"