summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/expression.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-07-22 16:36:29 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-07-22 16:36:29 -0400
commitfaa9b2c8da63aa116579fc6c43a30ce479b92ac2 (patch)
tree30a75f94f18a9f51197658e5b0a8d5ae1b09753d /lib/sqlalchemy/sql/expression.py
parent2bee05098e09dcdf09f7c8ff1c7efeba0c2fc9f2 (diff)
downloadsqlalchemy-faa9b2c8da63aa116579fc6c43a30ce479b92ac2.tar.gz
- [feature] Revised the rules used to determine
the operator precedence for the user-defined operator, i.e. that granted using the ``op()`` method. Previously, the smallest precedence was applied in all cases, now the default precedence is zero, lower than all operators except "comma" (such as, used in the argument list of a ``func`` call) and "AS", and is also customizable via the "precedence" argument on the ``op()`` method. [ticket:2537]
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r--lib/sqlalchemy/sql/expression.py41
1 files changed, 17 insertions, 24 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index ae25e8c7f..b9c149954 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -1931,34 +1931,32 @@ class CompareMixin(ColumnOperators):
right.type)
return BinaryExpression(left, right, op, type_=result_type)
-
# a mapping of operators with the method they use, along with their negated
# operator for comparison operators
operators = {
- operators.add : (__operate,),
- operators.mul : (__operate,),
- operators.sub : (__operate,),
- # Py2K
- operators.div : (__operate,),
- # end Py2K
- operators.mod : (__operate,),
- operators.truediv : (__operate,),
- operators.lt : (__compare, operators.ge),
- operators.le : (__compare, operators.gt),
- operators.ne : (__compare, operators.eq),
- operators.gt : (__compare, operators.le),
- operators.ge : (__compare, operators.lt),
- operators.eq : (__compare, operators.ne),
- operators.like_op : (__compare, operators.notlike_op),
- operators.ilike_op : (__compare, operators.notilike_op),
+ "add": (__operate,),
+ "mul": (__operate,),
+ "sub": (__operate,),
+ "div": (__operate,),
+ "mod": (__operate,),
+ "truediv": (__operate,),
+ "custom_op": (__operate,),
+ "lt": (__compare, operators.ge),
+ "le": (__compare, operators.gt),
+ "ne": (__compare, operators.eq),
+ "gt": (__compare, operators.le),
+ "ge": (__compare, operators.lt),
+ "eq": (__compare, operators.ne),
+ "like_op": (__compare, operators.notlike_op),
+ "ilike_op": (__compare, operators.notilike_op),
}
def operate(self, op, *other, **kwargs):
- o = CompareMixin.operators[op]
+ o = CompareMixin.operators[op.__name__]
return o[0](self, op, other[0], *o[1:], **kwargs)
def reverse_operate(self, op, other, **kwargs):
- o = CompareMixin.operators[op]
+ o = CompareMixin.operators[op.__name__]
return o[0](self, op, other, reverse=True, *o[1:], **kwargs)
def in_(self, other):
@@ -2100,11 +2098,6 @@ class CompareMixin(ColumnOperators):
return collate(self, collation)
- def op(self, operator):
- """See :meth:`.ColumnOperators.op`."""
-
- return lambda other: self.__operate(operator, other)
-
def _bind_param(self, operator, obj):
return BindParameter(None, obj,
_compared_to_operator=operator,