def _evaluate_expression(self, expr):
def cast_value(v):<EOL><INDENT>if isinstance(v, Decimal):<EOL><INDENT>return Fraction(v)<EOL><DEDENT>return v<EOL><DEDENT>total = cast_value(expr.offset)<EOL>for var, value in expr.values():<EOL><INDENT>value = cast_value(value)<EOL>if not isinstance(var, Product):<EOL><INDENT>total += self._get_value(var) * value<EOL><DEDENT>else:<EOL><INDENT>total += reduce(<EOL>operator.mul, (self._get_value(v) for v in var), value)<EOL><DEDENT><DEDENT>return total<EOL>
Evaluate an :class:`.Expression` using :meth:`_get_value`.