On Mon, Nov 23, 2020 at 6:29 AM Jonatan <pybots...@gmail.com> wrote: > > ```class A: > def __eq__(self, other): > return '__eq__' > > class B(A): > def __eq__(self, other): > print(super() == other) > print(super().__eq__(other)) > > B() == ...``` > > > OUTPUT: > False > __eq__ > > As you can see here, when you run the code, __uq__ does not get printed twice. > somehow, The expression "super() <OPERATOR> other" does not turn into > "super().__OPERATOR__(other)". > this bug is for any operator that you apply on super().
A super object isn't an instance of the parent class. It's a special placeholder that remembers the object and the current class, and will forward all method calls to that class. So when you try to do a comparison on it, what happens is something like this: s = super(B, self) comparison = type(s).__eq__(s, other) and then, if that comparison returns NotImplemented, tries the other way around, and various things, and then will return False. But at no time does it check s.__eq__, since comparisons like this are done using the type object, not the instance itself. Because of this, what you'll often see is that a dunder method delegates (with super) directly to a dunder method, not to the operator. Basically, like you do in your second line. :) > I'd be happy to hear from you why it happens and whether will it be fixed in > python3.10. Don't assume that it's a bug to be fixed :) It's a consequence of the way that method lookup is done for these kinds of things, and I doubt that that would be changing any time soon. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/OZ2JGWADZ6EJPVPIVUOS2CQPLGIIXNM4/ Code of Conduct: http://python.org/psf/codeofconduct/