From: Martin Ling Date: Tue, 11 Nov 2014 20:11:32 +0000 (+0000) Subject: python: Implement equality checks for EnumValue derived classes. X-Git-Tag: libsigrok-0.4.0~793 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f0c0dab5a9a463f87ca723cd4a4d6241311e0a0e;p=libsigrok.git python: Implement equality checks for EnumValue derived classes. Fixes bug #443. --- 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"