def _polymorphic(func):
@functools.wraps(func)
def wrapper(left, right):
- if isinstance(left, numbers.Rational):
- left = Rational(left)
- elif not isinstance(left, Expression):
- raise TypeError('left must be a a rational number '
- 'or a linear expression')
- if isinstance(right, numbers.Rational):
- right = Rational(right)
- elif not isinstance(right, Expression):
- raise TypeError('right must be a a rational number '
- 'or a linear expression')
+ if not isinstance(left, Expression):
+ if isinstance(left, numbers.Rational):
+ left = Rational(left)
+ else:
+ raise TypeError('left must be a a rational number '
+ 'or a linear expression')
+ if not isinstance(right, Expression):
+ if isinstance(right, numbers.Rational):
+ right = Rational(right)
+ else:
+ raise TypeError('right must be a a rational number '
+ 'or a linear expression')
return func(left, right)
return wrapper