From 041b2ef474a291c6b6172e49cc6e0d548e28761a Mon Sep 17 00:00:00 2001 From: Rolf de Vries Date: Mon, 26 Sep 2022 13:01:26 +0200 Subject: [PATCH] Add __pow__ and __rpow__ to operators.py --- lib/sqlalchemy/sql/operators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 49cf05f8de..92c1ec93b7 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -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} -- 2.47.2