]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112125: Fix None.__ne__(None) returning NotImplemented instead of False (#112504)
authorandrewluotechnologies <44252973+andrewluotechnologies@users.noreply.github.com>
Thu, 7 Dec 2023 12:56:01 +0000 (04:56 -0800)
committerGitHub <noreply@github.com>
Thu, 7 Dec 2023 12:56:01 +0000 (13:56 +0100)
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 bbf8544b09f0fb7c973cfb1915ba163d824b3f11..f983de5604963185249c3366f8e9774b440e117f 100644 (file)
@@ -135,6 +135,8 @@ extern PyObject* _Py_type_getattro_impl(PyTypeObject *type, PyObject *name,
                                         int *suppress_missing_attribute);
 extern PyObject* _Py_type_getattro(PyTypeObject *type, PyObject *name);
 
+extern PyObject* _Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int op);
+
 extern PyObject* _Py_slot_tp_getattro(PyObject *self, PyObject *name);
 extern PyObject* _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
 
index 558715383c82ee1665a740e490aa7195594ecfaf..5e66d58fd2cb18c0f6f1886c84a998658b51481e 100644 (file)
@@ -627,6 +627,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 d145674cb3ba34dc00108ce5620a06673e28c957..cdb7a08a7828fb741755c42698a752fcf253ffcc 100644 (file)
@@ -2026,7 +2026,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 aa00e04ad5e11b05fee989a096b12fb7ec2478ef..08f5f47d5867291425fdb533b8a23f510cd7d4d7 100644 (file)
@@ -5625,6 +5625,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)
 {