]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Added missing operators is_(), isnot()
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Sep 2012 20:14:58 +0000 (16:14 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Sep 2012 20:14:58 +0000 (16:14 -0400)
    to the ColumnOperators base, so that these long-available
    operators are present as methods like all
    the other operators.  [ticket:2544]

CHANGES
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/sql/operators.py
test/sql/test_operators.py

diff --git a/CHANGES b/CHANGES
index 3b600d5beedc21df0461a2eba61022ca88bd74e3..ee9f2da571fb89f4478438d46e87422660630a69 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -811,6 +811,11 @@ are also present in 0.8.
     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
index 6b80106018f3ba4d171cdd1b6126374cb6a4c62e..50f8061a649447072c0b4c02260245e973a2ee53 100644 (file)
@@ -2105,6 +2105,8 @@ class _DefaultColumnComparator(operators.ColumnOperators):
         "nullsfirst_op": (_scalar, nullsfirst),
         "nullslast_op": (_scalar, nullslast),
         "in_op": (_in_impl, operators.notin_op),
+        "is_": (_boolean_compare, operators.is_),
+        "isnot": (_boolean_compare, operators.isnot),
         "collate": (_collate_impl,),
         "match_op": (_match_impl,),
         "distinct_op": (_distinct_impl,),
index 38936231dc4a4579e7345004ae6cc01092107fed..ad9fa46688ec90364887c59988226dc9a28ed331 100644 (file)
@@ -368,6 +368,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.
 
index 4f56597913bbb7d4c7f9e6da676201800ee608ea..a6c99be43dd99b6a032bd9e9f6ce04ef5c04074e 100644 (file)
@@ -28,6 +28,10 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
             BinaryExpression(left, right, operator)
         )
 
+        assert operator(left, right).compare(
+            BinaryExpression(left, right, operator)
+        )
+
     def test_desc(self):
         self._do_scalar_test(operators.desc_op, desc)
 
@@ -37,6 +41,12 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
     def test_plus(self):
         self._do_operate_test(operators.add)
 
+    def test_is(self):
+        self._do_operate_test(operators.is_)
+
+    def test_isnot(self):
+        self._do_operate_test(operators.isnot)
+
     def test_no_getitem(self):
         assert_raises_message(
             NotImplementedError,