Reflected Operations
For the binary infix operators above, optype additionally provides
interfaces with reflected (swapped) operands, e.g. __radd__ is a reflected
__add__.
They are named like the original, but prefixed with CanR prefix, i.e.
__name__.replace('Can', 'CanR').
| operator | operand | |||
|---|---|---|---|---|
| expression | function | type | method | type |
x + _ |
do_radd |
DoesRAdd |
__radd__ |
CanRAdd[-T, +R=T]CanRAddSelf[-T]
|
x - _ |
do_rsub |
DoesRSub |
__rsub__ |
CanRSub[-T, +R=T]CanRSubSelf[-T]
|
x * _ |
do_rmul |
DoesRMul |
__rmul__ |
CanRMul[-T, +R=T]CanRMulSelf[-T]
|
x @ _ |
do_rmatmul |
DoesRMatmul |
__rmatmul__ |
CanRMatmul[-T, +R=T]CanRMatmulSelf[-T]
|
x / _ |
do_rtruediv |
DoesRTruediv |
__rtruediv__ |
CanRTruediv[-T, +R=T]CanRTruedivSelf[-T]
|
x // _ |
do_rfloordiv |
DoesRFloordiv |
__rfloordiv__ |
CanRFloordiv[-T, +R=T]CanRFloordivSelf[-T]
|
x % _ |
do_rmod |
DoesRMod |
__rmod__ |
CanRMod[-T, +R=T]CanRModSelf[-T]
|
divmod(x, _) |
do_rdivmod |
DoesRDivmod |
__rdivmod__ |
CanRDivmod[-T, +R] |
x ** _pow(x, _)
|
do_rpow |
DoesRPow |
__rpow__ |
CanRPow[-T, +R=T]CanRPowSelf[-T]
|
x << _ |
do_rlshift |
DoesRLshift |
__rlshift__ |
CanRLshift[-T, +R=T]CanRLshiftSelf[-T]
|
x >> _ |
do_rrshift |
DoesRRshift |
__rrshift__ |
CanRRshift[-T, +R=T]CanRRshiftSelf[-T]
|
x & _ |
do_rand |
DoesRAnd |
__rand__ |
CanRAnd[-T, +R=T]CanRAndSelf[-T]
|
x ^ _ |
do_rxor |
DoesRXor |
__rxor__ |
CanRXor[-T, +R=T]CanRXorSelf[-T]
|
x | _ |
do_ror |
DoesROr |
__ror__ |
CanROr[-T, +R=T]CanROrSelf[-T]
|
Note
CanRPow corresponds to CanPow2; the 3-parameter "modulo" pow does not reflect
in Python.
According to the relevant python docs:
Note that ternary
pow()will not try calling__rpow__()(the coercion rules would become too complicated).