In <[EMAIL PROTECTED]>, Rene Pijlman wrote: > Steven D'Aprano: >>Rene Pijlman: >>> Mr.Rech: >>>> def __eq__(self, other): >>>> try: >>>> return self.an_attribute == other.an_attribute >>>> except AttributeError: >>>> return False >>> >>> This may give unexpected results when you compare a foo with an instance >>> of a completely different type that happens to have an attribute called >>> 'an_attribute'. >> >>That's a trade-off, isn't it? >> >>On the one hand, you risk false negatives, by refusing to compare against >>things you didn't think of. > > Well no, when comparing against things you didn't think of the __eq__ > shouldn't return a false False, it should return NotImplemented. After > all, the things you didn't think of are not (yet) implemented.
I think Steven thinks that it is possible that you compare to an object of a different type which has the same attributes as expected by the `__eq__()` method. If the first test is `isinstance()` for the "correct" type you rule out those cases and give a false `False`. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list