From 249bc5be0038dcf69a94ad558d7bd4c1012a47c4 Mon Sep 17 00:00:00 2001 From: Dan Gittik Date: Fri, 17 Jul 2015 02:26:31 +0300 Subject: Added support for reflected modulo operator. --- lib/sqlalchemy/sql/operators.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 51f162c98..17a9d3086 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -597,6 +597,14 @@ class ColumnOperators(Operators): """ return self.reverse_operate(div, other) + def __rmod__(self, other): + """Implement the ``%`` operator in reverse. + + See :meth:`.ColumnOperators.__mod__`. + + """ + return self.reverse_operate(mod, other) + def between(self, cleft, cright, symmetric=False): """Produce a :func:`~.expression.between` clause against the parent object, given the lower and upper range. -- cgit v1.2.1 From ae6fd1c3899f8197250e84bae363c75d0116d082 Mon Sep 17 00:00:00 2001 From: Dan Gittik Date: Fri, 17 Jul 2015 02:28:23 +0300 Subject: Added test for modulo operator. --- test/sql/test_operators.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 0985020d1..65d1e3716 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -1327,6 +1327,9 @@ class MathOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL): else: self._test_math_op(operator.div, '/') + def test_math_op_mod(self): + self._test_math_op(operator.mod, '%') + class ComparisonOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL): __dialect__ = 'default' -- cgit v1.2.1