+def _polymorphic_method(func):
+ @functools.wraps(func)
+ def wrapper(self, other):
+ if isinstance(other, Value):
+ return func(self, other)
+ if isinstance(other, numbers.Rational):
+ other = Value(self.context, other)
+ return func(self, other)
+ raise TypeError('operand should be a Value or a Rational')
+ return wrapper