On Fri, Dec 18, 2020 at 5:02 AM Paul Sokolovsky <pmis...@gmail.com> wrote: > This is not some completely new restriction. For example, following > already doesn't work in Python: > > class A: > pass > > o = A() > o.__add__ = lambda self, x: print("me called") > > o + A() # lambda above is never called >
But the addition operator isn't just calling __add__, so this IS a completely new restriction. You're comparing unrelated things. class A: def __add__(self, other): print("I got called") class B(A): def __add__(self, other): print("Actually I did") A() + B() The operator delegation mechanism doesn't use the class as a means of optimization. It does it because it is the language specification to do so. I said I wasn't going to respond, but this one is SUCH a common misunderstanding that I don't want people led astray by it. "a+b" is NOT implemented as "a.__add__(b)", nor as "type(a).__add__(b)"! Can this thread move off python-ideas and onto pycopy-ideas please? It's not really talking about Python any more, it just pretends to be. 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/KWNAJHZ4YAT7IHHBHVA6HBQHLKF22HQR/ Code of Conduct: http://python.org/psf/codeofconduct/