This is useful in the context of reducing the available methods and operator
overloading, when subclassing a type.
Typically, when subclassing a NamedTuple type, you often don't want the <, >,
<=, >=, + or * operators to work, so in that case you would want for the
related methods to return NotImplemented.
This can be done with (and I hope triple-backquotes markdown works here) :
```py
def NotImplementedMethod(self, other):
return NotImplemented
class ...:
...
__le__ = __lt__ = __ge__ = __gt__ = __mul__ = __rmul__ = __add__ = __radd__
= NotImplementedMethod
```
This is very handy, and I think it should be added to the builtins.
A simple way to implement this could be to have `NotImplemented(a, b)` return
NotImplemented for any value of a and b, so that NotImplemented can be used
instead of NotImplementedMethod in the above example.
A caveat for that version, and the reason I would not recommand it, is that it
makes NotImplemented a callable when it doesn't need to be, and probably
shouldn't be.
The other way around, which I'm recommanding, is to add the
NotImplementedMethod, working as-is but implement it in C, so that it has no
inner dict, is lightweight and less prone to programmer mismanagement (making
it a builtin_function_or_method instead of a function).
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/EAO5JSJBIHEPF5QP22TRE4KYNGF2SSBH/
Code of Conduct: http://python.org/psf/codeofconduct/