Reversed ops in operator module

Why would it be ‘nice’, especially when you can trivially implement such?

The operator module exposes the C functions that implement the operators. Each C function calls the normal and reversed dunder methods as appropriate. There are no reversed functions to expose.

IOW, a+b is compiled, in CPython, to a binary add functions that may call either a.__add__(b) or b.__radd__(a) or both as appropriate and necessary.

2 Likes