diff options
Diffstat (limited to '')
-rw-r--r-- | polymatrix/expression/expression.py | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/polymatrix/expression/expression.py b/polymatrix/expression/expression.py index edb0830..3c52297 100644 --- a/polymatrix/expression/expression.py +++ b/polymatrix/expression/expression.py @@ -117,31 +117,25 @@ class Expression(ExpressionBaseMixin, ABC): def _binary(op, left, right): stack = get_stack_lines() - if isinstance(left, Expression): - right = polymatrix.expression.init.init_from_expr_or_none(right) + if isinstance(left, Expression) and isinstance(right, Expression): + return left.copy(underlying=op(left.underlying, right.underlying, stack)) - # delegate to upper level + elif isinstance(left, Expression): + right = polymatrix.expression.init.init_from_expr_or_none(right) - # NP: what is upper level? Class inherits from ABC and base class, - # NP: neither has binary operators, also NotImplemented IIRC is only for __lt__ - # NP: and other comparison methods and not for overloadings like __add__ if right is None: return NotImplemented - return left.copy( - underlying=op(left, right, stack), - ) + return left.copy(underlying=op(left.underlying, right, stack)) + # else right is an Expression else: left = polymatrix.expression.init.init_from_expr_or_none(left) - # delegate to upper level if left is None: return NotImplemented - return right.copy( - underlying=op(left, right, stack), - ) + return right.copy( underlying=op(left, right.underlying, stack)) def cache(self) -> "Expression": return self.copy( |