]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-112125: Fix None.__ne__(None) returning NotImplemented instead of … (#112827)
authorVictor Stinner <vstinner@python.org>
Thu, 7 Dec 2023 13:41:00 +0000 (14:41 +0100)
committerGitHub <noreply@github.com>
Thu, 7 Dec 2023 13:41:00 +0000 (13:41 +0000)
gh-112125: Fix None.__ne__(None) returning NotImplemented instead of False (#112504)

(cherry picked from commit 9c3458e05865093dd55d7608810a9d0ef0765978)

Co-authored-by: andrewluotechnologies <44252973+andrewluotechnologies@users.noreply.github.com>
Include/internal/pycore_typeobject.h
Lib/test/test_builtin.py
Misc/NEWS.d/next/Core and Builtins/2023-12-07-13-19-55.gh-issue-112125.4ADN7i.rst [new file with mode: 0644]
Objects/object.c
Objects/typeobject.c

index 8f3fbbcdb5ffcd91400f6f59f538ba7614d56108..63f76fc55c9b274a0c858630ad065c92a2e7a34c 100644 (file)
@@ -133,6 +133,8 @@ _Py_type_getattro_impl(PyTypeObject *type, PyObject *name, int *suppress_missing
 PyObject *
 _Py_type_getattro(PyTypeObject *type, PyObject *name);
 
+extern PyObject* _Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int op);
+
 PyObject *_Py_slot_tp_getattro(PyObject *self, PyObject *name);
 PyObject *_Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
 
index c3857195177b569a313f8abe98d33e5bd510ca75..de83b523f986e1531da74b909f5ebdd1892c9420 100644 (file)
@@ -602,6 +602,11 @@ class BuiltinTest(unittest.TestCase):
         # test that object has a __dir__()
         self.assertEqual(sorted([].__dir__()), dir([]))
 
+    def test___ne__(self):
+        self.assertFalse(None.__ne__(None))
+        self.assertTrue(None.__ne__(0))
+        self.assertTrue(None.__ne__("abc"))
+
     def test_divmod(self):
         self.assertEqual(divmod(12, 7), (1, 5))
         self.assertEqual(divmod(-12, 7), (-2, 2))
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-12-07-13-19-55.gh-issue-112125.4ADN7i.rst b/Misc/NEWS.d/next/Core and Builtins/2023-12-07-13-19-55.gh-issue-112125.4ADN7i.rst
new file mode 100644 (file)
index 0000000..52cd450
--- /dev/null
@@ -0,0 +1 @@
+Fix None.__ne__(None) returning NotImplemented instead of False
index 8a4010fb13669bfda1d45b62a6a7155fe44a2f6d..aac707d6a26cb62099e162547d88c4cad3570a99 100644 (file)
@@ -1878,7 +1878,7 @@ PyTypeObject _PyNone_Type = {
     0,                  /*tp_doc */
     0,                  /*tp_traverse */
     0,                  /*tp_clear */
-    0,                  /*tp_richcompare */
+    _Py_BaseObject_RichCompare, /*tp_richcompare */
     0,                  /*tp_weaklistoffset */
     0,                  /*tp_iter */
     0,                  /*tp_iternext */
index d0c7c5f9439ccc0fd71546027e6529f304106fe7..71d20687479aab560fbce230449a5ef9bb354115 100644 (file)
@@ -5593,6 +5593,12 @@ object_richcompare(PyObject *self, PyObject *other, int op)
     return res;
 }
 
+PyObject*
+_Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int op)
+{
+    return object_richcompare(self, other, op);
+}
+
 static PyObject *
 object_get_class(PyObject *self, void *closure)
 {