En Tue, 15 Sep 2009 11:18:33 -0300, Jason <jason.hee...@gmail.com> escribió:

Comparing a string to the enumerations in pysvn gives me an attribute
error, because they've overloaded the rich compare methods:

import pysvn
"string" in [pysvn.wc_notify_action.status_completed, "string"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: expecting wc_notify_action object for rich compare

Is there a simple way around this?

Looks like a bug in pysvn. Some class (whatever pysvn.wc_notify_action.status_completed is) is not well written. When compared against something unknown, it should return NotImplemented instead of raising AttributeError.

py> class BadBoy(object):
...   foo = 1
...   #
...   def __eq__(self, other):
...     if not isinstance(other, BadBoy):
...       raise TypeError, "expecting BadBoy object for rich compare"
...     return self.foo==other.foo
...
py> "hello" in [BadBoy(), "hello"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in __eq__
TypeError: expecting BadBoy object for rich compare
py>
py> class GoodBoy(object):
...   foo = 1
...   #
...   def __eq__(self, other):
...     if not isinstance(other, GoodBoy):
...       return NotImplemented
...     return self.foo==other.foo
...
py> "hello" in [GoodBoy(), "hello"]
True

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to