New submission from Mark Dickinson <dicki...@gmail.com>: Here's some strange behaviour in py3k:
newton:py3k dickinsm$ ./python.exe Python 3.2a0 (py3k:75015, Sep 22 2009, 16:25:12) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def __eq__(self, other): ... print("In A.__eq__", self, other) ... return NotImplemented ... >>> class B: ... def __eq__(self, other): ... print("In B.__eq__", self, other) ... return NotImplemented ... >>> A() == B() In A.__eq__ <__main__.A object at 0x34d030> <__main__.B object at 0x448210> In B.__eq__ <__main__.B object at 0x448210> <__main__.A object at 0x34d030> In B.__eq__ <__main__.B object at 0x448210> <__main__.A object at 0x34d030> In A.__eq__ <__main__.A object at 0x34d030> <__main__.B object at 0x448210> False I'd expect to see only one call to A.__eq__ and one call to B.__eq__. The cause seems to be that: - slot_tp_richcompare (in typeobject.c) makes two calls to half_richcompare, one with the original arguments and one with reverse arguments, *and* - do_richcompare (in object.c) also makes two calls to the tp_richcompare slot; again, one with the original arguments and one with the reversed arguments. I tried removing the second block of slot_tp_richcompare (still in py3k); make and make test succeeded without any problems. Removing this block does change behaviour though, so probably should not happen until 3.2, given that no-one appears to have reported the current behaviour actually causing any problems. The duplicate calls also exist in 2.x; figuring out a solution there (and being sure that the solution does the right thing) looks complicated, thanks to all the rich-compare/three-way-compare interactions. ---------- components: Interpreter Core messages: 93000 nosy: mark.dickinson severity: normal stage: needs patch status: open title: Redundant calls made to comparison methods. type: behavior versions: Python 2.7, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6970> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com