python: Implement equality checks for EnumValue derived classes.

Fixes bug #443.
This commit is contained in:
Martin Ling 2014-11-11 20:11:32 +00:00 committed by Uwe Hermann
parent 7a36ceacb9
commit f0c0dab5a9
1 changed files with 16 additions and 0 deletions

View 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"