Skip to content

Commit

Permalink
Remove reverse operators (radd, rmul, ...)
Browse files Browse the repository at this point in the history
Implemented reverse operators with forward operators
and reversed arguments:

__radd__(a, b) = __add__(b, a)
  • Loading branch information
maurosilber committed Aug 7, 2023
1 parent 5b364d4 commit eb985ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions symbolite/abstract/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,55 +184,55 @@ def __xor__(self, other: Any) -> Self:
# Reflected arithmetic operators
def __radd__(self, other: Any) -> Self:
"""Implements reflected addition."""
return radd(self, other)
return add(other, self)

def __rsub__(self, other: Any) -> Self:
"""Implements reflected subtraction."""
return rsub(self, other)
return sub(other, self)

def __rmul__(self, other: Any) -> Self:
"""Implements reflected multiplication."""
return rmul(self, other)
return mul(other, self)

def __rmatmul__(self, other: Any) -> Self:
"""Implements reflected multiplication."""
return rmatmul(self, other)
return matmul(other, self)

def __rtruediv__(self, other: Any) -> Self:
"""Implements reflected true division."""
return rtruediv(self, other)
return truediv(other, self)

def __rfloordiv__(self, other: Any) -> Self:
"""Implements reflected integer division using the // operator."""
return rfloordiv(self, other)
return floordiv(other, self)

def __rmod__(self, other: Any) -> Self:
"""Implements reflected modulo using the % operator."""
return rmod(self, other)
return mod(other, self)

def __rpow__(self, other: Any) -> Self:
"""Implements behavior for reflected exponents using the ** operator."""
return rpow(self, other)
return pow(other, self)

def __rlshift__(self, other: Any) -> Self:
"""Implements reflected left bitwise shift using the << operator."""
return rlshift(self, other)
return lshift(other, self)

def __rrshift__(self, other: Any) -> Self:
"""Implements reflected right bitwise shift using the >> operator."""
return rrshift(self, other)
return rshift(other, self)

def __rand__(self, other: Any) -> Self:
"""Implements reflected bitwise and using the & operator."""
return rand(self, other)
return and_(other, self)

def __ror__(self, other: Any) -> Self:
"""Implements reflected bitwise or using the | operator."""
return ror(self, other)
return or_(other, self)

def __rxor__(self, other: Any) -> Self:
"""Implements reflected bitwise xor using the ^ operator."""
return rxor(self, other)
return xor(other, self)

# Unary operators and functions
def __neg__(self) -> Self:
Expand Down
4 changes: 2 additions & 2 deletions symbolite/testsuite/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_forward_reverse():

expr = 1 + x
assert isinstance(expr.expression, Expression)
assert expr.expression.func.name == "radd"
assert expr.expression.args == (x, 1)
assert expr.expression.func.name == "add"
assert expr.expression.args == (1, x)


@pytest.mark.parametrize(
Expand Down

0 comments on commit eb985ef

Please sign in to comment.