]> sigrok.org Git - libsigrok.git/commitdiff
python: Implement equality checks for EnumValue derived classes.
authorMartin Ling <redacted>
Tue, 11 Nov 2014 20:11:32 +0000 (20:11 +0000)
committerUwe Hermann <redacted>
Wed, 12 Nov 2014 01:27:05 +0000 (02:27 +0100)
Fixes bug #443.

bindings/python/sigrok/core/classes.i

index 066dbf8264f8edc75b641d29c217ec5913b1b8bb..b05f21e1be0284ea5454b8fbac7cf9020557c304 100644 (file)
@@ -382,6 +382,22 @@ std::map<std::string, Glib::VariantBase> 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"