On Tue, Mar 7, 2017 at 4:53 PM David Mertz <me...@gnosis.cx> wrote: > > > In [22]: class Eq(int): > def __eq__(self, other): > return True > ....: > In [23]: four, five, six = Eq(4), Eq(5), Eq(6) > In [24]: lst = [four, five, six] > In [25]: lst.count(Eq(7)) > Out[25]: 3 > > > How would this work (other than saying "don't do that it's perverse")? >
There would be two needless checks in the equality testing. First, PyObject_RichCompareBool would see if other is a subclass of self, in which case other->tp_richcompare would be used iff. it is non-null. Otherwise, we would check if self->tp_richcompare is non-null, the check would pass, and we would call self.__eq__. See the flow chart on my poster (linked to in the first email on this thread).
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/