]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add __pow__ and __rpow__ to operators.py 8580/head
authorRolf de Vries <Rolf_d_v@hotmail.com>
Mon, 26 Sep 2022 11:01:26 +0000 (13:01 +0200)
committerGitHub <noreply@github.com>
Mon, 26 Sep 2022 11:01:26 +0000 (13:01 +0200)
lib/sqlalchemy/sql/operators.py

index 49cf05f8defc3c71568ec34fc4a39fcda82b9e26..92c1ec93b77fb38276203381e2e170d25dfdc0a9 100644 (file)
@@ -30,6 +30,7 @@ from operator import mul as _uncast_mul
 from operator import ne as _uncast_ne
 from operator import neg as _uncast_neg
 from operator import or_ as _uncast_or_
+from operator import pow as _uncast_pow
 from operator import rshift as _uncast_rshift
 from operator import sub as _uncast_sub
 from operator import truediv as _uncast_truediv
@@ -91,6 +92,7 @@ mul = cast(OperatorType, _uncast_mul)
 ne = cast(OperatorType, _uncast_ne)
 neg = cast(OperatorType, _uncast_neg)
 or_ = cast(OperatorType, _uncast_or_)
+pow = cast(OperatorType, _uncast_pow)
 rshift = cast(OperatorType, _uncast_rshift)
 sub = cast(OperatorType, _uncast_sub)
 truediv = cast(OperatorType, _uncast_truediv)
@@ -1706,6 +1708,20 @@ class ColumnOperators(Operators):
         """
         return self.reverse_operate(floordiv, other)
 
+        def __pow__(self, other) -> ColumnOperators:
+        """Implement the ``**`` operator.
+
+        In a column context, produces the clause ``pow(a, b)``
+        """
+        return self.operate(pow, other)
+
+    def __rpow__(self, other) -> ColumnOperators:
+        """Implement the ``**`` operator in reverse.
+
+        See :meth:`.ColumnOperators.__pow__`.
+
+        """
+
 
 _commutative: Set[Any] = {eq, ne, add, mul}
 _comparison: Set[Any] = {eq, ne, lt, gt, ge, le}