From: Rolf de Vries Date: Mon, 26 Sep 2022 11:01:26 +0000 (+0200) Subject: Add __pow__ and __rpow__ to operators.py X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8580%2Fhead;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add __pow__ and __rpow__ to operators.py --- 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}