Hello,

On Fri, 18 Dec 2020 06:09:56 +1100
Chris Angelico <ros...@gmail.com> wrote:

> 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.

No, you're just shifting discussion to something else. Special methods
assigned to object instances aren't get called in general. If you can
show how to assign an arbitrary dunder method to an instance and get it
called by operator, please do that. Otherwise, that was exactly the
point to show.   

> 
> 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.

So, the language specification for the "strict execution mode" will say
that "the only way to define a method is syntactically in the class
body". What's your problem with that? You often assign your methods to
individual instances after they're created? Please speak up and explain
us your usecases.

[]

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
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/RMSY4P42YVOXC3ZRT6SDRUOKNOZVL2JX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to