arskom/spyne — pull request #254 by FeiWongReed (2013-07-22 06:37:20+00:00)
Title: Fix for bad enum comparison

For now the following test works incorrectly with spyne:

```python
from spyne.model.enum import Enum
Jopa = Enum(u"foo", u"bar", u"baz", type_name='Jopa')
assert Jopa.foo == "XXX"
```

This assert unexpectedly passes. This happens due to incorrect implementation of __cmp__ method in spyne.model.Enum:

```python
return isinstance(self, type(other)) and cmp(self.__value, other.__value)
```

So for any non-enum instance cmp will return zero that will be treated as sign of equality. Look at http://docs.python.org/2/reference/datamodel.html#object.__cmp__ for details.

The correct solution is to compare with another types by id(). Warning: don't try to just call cmp(this, other), such approach will cause infinite recursion.

Also note that __cmp__ method is deprecated in python3 and "rich comparison functions" must be implemented to migrate onto.