For example, if I wanted to apply mathematical operations on objects as follows:
class A(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return value
assert(A(1) + A(2) == 3)
I get the following error: TypeError: unsupported operand type(s) for +: 'A' and 'A'
Is it possible to evaluate objects for primitives so that I can apply simple operations to them? Similarly, as you could use implicit conversionsin Scala.
source
share