summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/default_comparator.py8
-rw-r--r--lib/sqlalchemy/sql/operators.py3
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py4
3 files changed, 11 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py
index 4ba53ef75..4485c661b 100644
--- a/lib/sqlalchemy/sql/default_comparator.py
+++ b/lib/sqlalchemy/sql/default_comparator.py
@@ -50,11 +50,15 @@ def _boolean_compare(expr, op, obj, negate=None, reverse=False,
if op in (operators.eq, operators.is_):
return BinaryExpression(expr, _const_expr(obj),
operators.is_,
- negate=operators.isnot)
+ negate=operators.isnot,
+ type_=result_type
+ )
elif op in (operators.ne, operators.isnot):
return BinaryExpression(expr, _const_expr(obj),
operators.isnot,
- negate=operators.is_)
+ negate=operators.is_,
+ type_=result_type
+ )
else:
raise exc.ArgumentError(
"Only '=', '!=', 'is_()', 'isnot()', "
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 49642acdd..58f32b3e6 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -1021,7 +1021,8 @@ def json_path_getitem_op(a, b):
_commutative = {eq, ne, add, mul}
-_comparison = {eq, ne, lt, gt, ge, le, between_op, like_op}
+_comparison = {eq, ne, lt, gt, ge, le, between_op, like_op, is_,
+ isnot, is_distinct_from, isnot_distinct_from}
def is_comparison(op):
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index b8117e3ca..b8c8c8116 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -2555,7 +2555,9 @@ class NullType(TypeEngine):
class Comparator(TypeEngine.Comparator):
def _adapt_expression(self, op, other_comparator):
- if isinstance(other_comparator, NullType.Comparator) or \
+ if operators.is_comparison(op):
+ return op, BOOLEANTYPE
+ elif isinstance(other_comparator, NullType.Comparator) or \
not operators.is_commutative(op):
return op, self.expr.type
else: