]> sigrok.org Git - libsigrok.git/blobdiff - bindings/python/sigrok/core/classes.i
python: Implement equality checks for EnumValue derived classes.
[libsigrok.git] / 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"