Enhance ValueHolder with missing underscore methods.
This commit is contained in:
@ -17,6 +17,14 @@ class Wrapper:
|
||||
|
||||
|
||||
class ValueHolder:
|
||||
"""
|
||||
Decorator holding a value in a given memory adress, effectively allowing to "hold" even an immutable typed value as the state of a
|
||||
node, allowing different actors to mutate it durably.
|
||||
|
||||
For the sake of concistency, all operator methods have been implemented (see https://docs.python.org/3/reference/datamodel.html) or
|
||||
at least all in a certain category, but it feels like a more correct method should exist, like with a getattr-something on the
|
||||
value. Let's see later.
|
||||
"""
|
||||
def __init__(self, value, *, type=None):
|
||||
self.value = value
|
||||
self.type = type
|
||||
@ -84,18 +92,93 @@ class ValueHolder:
|
||||
def __itruediv__(self, other):
|
||||
self.value /= other
|
||||
|
||||
def __floordiv__(self, other):
|
||||
return self.value // other
|
||||
|
||||
"""
|
||||
object.__matmul__(self, other)
|
||||
object.__truediv__(self, other)
|
||||
object.__floordiv__(self, other)
|
||||
object.__mod__(self, other)
|
||||
object.__divmod__(self, other)
|
||||
object.__pow__(self, other[, modulo])
|
||||
object.__lshift__(self, other)
|
||||
object.__rshift__(self, other)
|
||||
object.__and__(self, other)
|
||||
object.__xor__(self, other)
|
||||
object.__or__(self, other)
|
||||
def __rfloordiv__(self, other):
|
||||
return other // self.value
|
||||
|
||||
def __ifloordiv__(self, other):
|
||||
self.value //= other
|
||||
|
||||
def __mod__(self, other):
|
||||
return self.value % other
|
||||
|
||||
def __rmod__(self, other):
|
||||
return other % self.value
|
||||
|
||||
def __imod__(self, other):
|
||||
self.value %= other
|
||||
|
||||
def __divmod__(self, other):
|
||||
return divmod(self.value, other)
|
||||
|
||||
def __rdivmod__(self, other):
|
||||
return divmod(other, self.value)
|
||||
|
||||
def __pow__(self, other):
|
||||
return self.value ** other
|
||||
|
||||
def __rpow__(self, other):
|
||||
return other ** self.value
|
||||
|
||||
def __ipow__(self, other):
|
||||
self.value **= other
|
||||
|
||||
def __lshift__(self, other):
|
||||
return self.value << other
|
||||
|
||||
def __rlshift__(self, other):
|
||||
return other << self.value
|
||||
|
||||
def __ilshift__(self, other):
|
||||
self.value <<= other
|
||||
|
||||
def __rshift__(self, other):
|
||||
return self.value >> other
|
||||
|
||||
def __rrshift__(self, other):
|
||||
return other >> self.value
|
||||
|
||||
def __irshift__(self, other):
|
||||
self.value >>= other
|
||||
|
||||
def __and__(self, other):
|
||||
return self.value & other
|
||||
|
||||
def __rand__(self, other):
|
||||
return other & self.value
|
||||
|
||||
def __iand__(self, other):
|
||||
self.value &= other
|
||||
|
||||
def __xor__(self, other):
|
||||
return self.value ^ other
|
||||
|
||||
def __rxor__(self, other):
|
||||
return other ^ self.value
|
||||
|
||||
def __ixor__(self, other):
|
||||
self.value ^= other
|
||||
|
||||
def __or__(self, other):
|
||||
return self.value | other
|
||||
|
||||
def __ror__(self, other):
|
||||
return other | self.value
|
||||
|
||||
def __ior__(self, other):
|
||||
self.value |= other
|
||||
|
||||
def __neg__(self):
|
||||
return -self.value
|
||||
|
||||
def __pos__(self):
|
||||
return +self.value
|
||||
|
||||
def __abs__(self):
|
||||
return abs(self.value)
|
||||
|
||||
def __invert__(self):
|
||||
return ~self.value
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user