Given a simple class like
class Vector(object):
def __init__(self, value):
self.value = value
def __abs__(self):
return math.sqrt(sum([x**2 for x in self.value]))
def __round__(self, *n):
return [round(x,*n) for x in self.value]
why does abs(Vector([-3,4])) correctly yield 5 while round(Vector([-3.1,4])) complains with a TypeError: a float is required instead of the desired [-3,4], and how can this be fixed?
I know round should usually return a float, but for a vector as in this example there is probably no ambiguity on the possible meaning, so why can this not be simply overridden? Do I really have to subclass numbers.Real, or define Vector(...).round(n) instead?