On Tue, Dec 3, 2019, at 11:36, Ricky Teachey wrote:
>  
> > What if there was a general mechanism to allow operators to be implemented 
> > by user code that does not belong to the class?
> > 
> >  If the name [e.g.] __operatorhook_or__ is defined anywhere in a module, 
> > within that module all calls to that operator are replaced with a two-step 
> > process:
> > 
> 
> * within that module * 
> 
> So this would not happen in other modules when that module was 
> imported...? But would this mean that if I wanted the operation be 
> effective for all modules, I would either have to define it in every 
> module I have written, or import the function by name? E.g.:

I figured this was the lesser evil, vs two different modules that want to 
define an operator differently interfering with each other, or a badly written 
one interfering with a stdlib module... it also allows modules that don't use 
the facility to not have to pay for it, since overriding an operator like 
__getattr__ or __call__ in this way would have an enormous performance cost.

This also allows you to get the original operator if you need it by importing 
from the 'operator' module.

> # mod1
> def __operatorhook_or__(obj1, obj2): ...
> 
> # mod2
> from mod1 import __operatorhook_or__
_______________________________________________
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/IVTSKHTPI5JPICQEY2XGGMPOI557IQSB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to