Skip to content

Inplace Operations

Similar to the reflected ops, the inplace/augmented ops are prefixed with CanI, namely:

operator operand
expression function type method types
_ += x do_iadd DoesIAdd __iadd__ CanIAdd[-T, +R]
CanIAddSelf[-T]
CanIAddSame[-T?]
_ -= x do_isub DoesISub __isub__ CanISub[-T, +R]
CanISubSelf[-T]
CanISubSame[-T?]
_ *= x do_imul DoesIMul __imul__ CanIMul[-T, +R]
CanIMulSelf[-T]
CanIMulSame[-T?]
_ @= x do_imatmul DoesIMatmul __imatmul__ CanIMatmul[-T, +R]
CanIMatmulSelf[-T]
CanIMatmulSame[-T?]
_ /= x do_itruediv DoesITruediv __itruediv__ CanITruediv[-T, +R]
CanITruedivSelf[-T]
CanITruedivSame[-T?]
_ //= x do_ifloordiv DoesIFloordiv __ifloordiv__ CanIFloordiv[-T, +R]
CanIFloordivSelf[-T]
CanIFloordivSame[-T?]
_ %= x do_imod DoesIMod __imod__ CanIMod[-T, +R]
CanIModSelf[-T]
CanIModSame[-T?]
_ **= x do_ipow DoesIPow __ipow__ CanIPow[-T, +R]
CanIPowSelf[-T]
CanIPowSame[-T?]
_ <<= x do_ilshift DoesILshift __ilshift__ CanILshift[-T, +R]
CanILshiftSelf[-T]
CanILshiftSame[-T?]
_ >>= x do_irshift DoesIRshift __irshift__ CanIRshift[-T, +R]
CanIRshiftSelf[-T]
CanIRshiftSame[-T?]
_ &= x do_iand DoesIAnd __iand__ CanIAnd[-T, +R]
CanIAndSelf[-T]
CanIAndSame[-T?]
_ ^= x do_ixor DoesIXor __ixor__ CanIXor[-T, +R]
CanIXorSelf[-T]
CanIXorSame[-T?]
_ |= x do_ior DoesIOr __ior__ CanIOr[-T, +R]
CanIOrSelf[-T]
CanIOrSame[-T?]

These inplace operators usually return themselves (after some in-place mutation). But unfortunately, it currently isn't possible to use Self for this (i.e. something like type MyAlias[T] = optype.CanIAdd[T, Self] isn't allowed). So to help ease this unbearable pain, optype comes equipped with ready-made aliases for you to use. They bear the same name, with an additional *Self suffix, e.g. optype.CanIAddSelf[T].

Note

The CanI*Self protocols method return typing.Self and optionally accept T. The CanI*Same protocols also return Self, but instead accept rhs: Self | T. Since T defaults to Never, it will accept rhs: Self | Never if T is not provided, which is equivalent to rhs: Self.

Available since 0.12.1