From 1b12c86900b90ed649210a92cc13826b1ac35e14 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 22 Sep 2012 16:31:32 -0400 Subject: [PATCH] - [bug] Added missing operators is_(), isnot() to the ColumnOperators base, so that these long-available operators are present as methods like all the other operators. [ticket:2544] --- CHANGES | 5 +++++ lib/sqlalchemy/sql/expression.py | 3 ++- lib/sqlalchemy/sql/operators.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d3ef996894..e16f995e3c 100644 --- a/CHANGES +++ b/CHANGES @@ -102,6 +102,11 @@ CHANGES here, so this has been re-instated and of course tested. [ticket:2558] + - [bug] Added missing operators is_(), isnot() + to the ColumnOperators base, so that these long-available + operators are present as methods like all + the other operators. [ticket:2544] + - engine - [bug] Fixed bug whereby a disconnect detect + dispose that occurs diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 3dec4bca89..0dd95b3369 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1910,7 +1910,8 @@ class _CompareMixin(ColumnOperators): operators.eq : (__compare, operators.ne), operators.like_op : (__compare, operators.notlike_op), operators.ilike_op : (__compare, operators.notilike_op), - + operators.is_ : (__compare, operators.is_), + operators.isnot : (__compare, operators.isnot), } def operate(self, op, *other, **kwargs): diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 437358a104..32620bf906 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -284,6 +284,36 @@ class ColumnOperators(Operators): """ return self.operate(in_op, other) + def is_(self, other): + """Implement the ``IS`` operator. + + Normally, ``IS`` is generated automatically when comparing to a + value of ``None``, which resolves to ``NULL``. However, explicit + usage of ``IS`` may be desirable if comparing to boolean values + on certain platforms. + + .. versionadded:: 0.7.9 + + .. seealso:: :meth:`.ColumnOperators.isnot` + + """ + return self.operate(is_, other) + + def isnot(self, other): + """Implement the ``IS NOT`` operator. + + Normally, ``IS NOT`` is generated automatically when comparing to a + value of ``None``, which resolves to ``NULL``. However, explicit + usage of ``IS NOT`` may be desirable if comparing to boolean values + on certain platforms. + + .. versionadded:: 0.7.9 + + .. seealso:: :meth:`.ColumnOperators.is_` + + """ + return self.operate(isnot, other) + def startswith(self, other, **kwargs): """Implement the ``startwith`` operator. -- 2.47.2