aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorPaul Sokolovsky2017-09-10 17:05:20 +0300
committerPaul Sokolovsky2017-09-10 17:05:57 +0300
commiteb84a830df62813f5af7f0144fc77444bf18f3a8 (patch)
treec75036150f3584486bc2064572faa2fe2750ae8c /py/objtype.c
parentde981040b392685b0d7f2381a63526b71e633b9c (diff)
py/runtime: Implement dispatch for "reverse op" special methods.
If, for class X, X.__add__(Y) doesn't exist (or returns NotImplemented), try Y.__radd__(X) instead. This patch could be simpler, but requires undoing operand swap and operation switch to get non-confusing error message in case __radd__ doesn't exist.
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 8ce593dba..cf9311d5c 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -441,6 +441,13 @@ const qstr mp_binary_op_method_name[] = {
MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
MP_BINARY_OP_INPLACE_MODULO,
MP_BINARY_OP_INPLACE_POWER,*/
+
+ #if MICROPY_PY_REVERSE_SPECIAL_METHODS
+ [MP_BINARY_OP_REVERSE_ADD] = MP_QSTR___radd__,
+ [MP_BINARY_OP_REVERSE_SUBTRACT] = MP_QSTR___rsub__,
+ [MP_BINARY_OP_REVERSE_MULTIPLY] = MP_QSTR___rmul__,
+ #endif
+
[MP_BINARY_OP_LESS] = MP_QSTR___lt__,
[MP_BINARY_OP_MORE] = MP_QSTR___gt__,
[MP_BINARY_OP_EQUAL] = MP_QSTR___eq__,