]> granicus.if.org Git - python/commitdiff
Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
authorRaymond Hettinger <python@rcn.com>
Wed, 19 Mar 2008 17:45:19 +0000 (17:45 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 19 Mar 2008 17:45:19 +0000 (17:45 +0000)
Lib/test/test_py3kwarn.py
Objects/listobject.c

index cb450ff14be7e3a20950900e09ac8d4a88d04817..f7a6949b1308cd252e200118a3fad1fdf22f3471 100644 (file)
@@ -91,6 +91,20 @@ class TestPy3KWarnings(unittest.TestCase):
     def assertWarning(self, _, warning, expected_message):
         self.assertEqual(str(warning.message), expected_message)
 
+    def test_sort_cmp_arg(self):
+        expected = "In 3.x, the cmp argument is no longer supported."
+        lst = range(5)
+        cmp = lambda x,y: -1
+
+        with catch_warning() as w:
+            self.assertWarning(lst.sort(cmp=cmp), w, expected)
+        with catch_warning() as w:
+            self.assertWarning(sorted(lst, cmp=cmp), w, expected)
+        with catch_warning() as w:
+            self.assertWarning(lst.sort(cmp), w, expected)
+        with catch_warning() as w:
+            self.assertWarning(sorted(lst, cmp), w, expected)
+
 def test_main():
     run_unittest(TestPy3KWarnings)
 
index 9e8659210122921e5b2df293a0e1121e782ca945..d4faf0a15e46f86033688b40c016e6c79d2234f6 100644 (file)
@@ -2037,7 +2037,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
        }
        if (compare == Py_None)
                compare = NULL;
-       if (compare == NULL && 
+       if (compare != NULL && 
             Py_Py3kWarningFlag &&
            PyErr_Warn(PyExc_DeprecationWarning, 
                       "In 3.x, the cmp argument is no longer supported.") < 0)