From: Victor Stinner Date: Thu, 7 Dec 2023 13:41:00 +0000 (+0100) Subject: [3.12] gh-112125: Fix None.__ne__(None) returning NotImplemented instead of … (#112827) X-Git-Tag: v3.12.1~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f27271619e7606338d194d669bbab4823517f7be;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-112125: Fix None.__ne__(None) returning NotImplemented instead of … (#112827) 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> --- diff --git a/Include/internal/pycore_typeobject.h b/Include/internal/pycore_typeobject.h index 8f3fbbcdb5ff..63f76fc55c9b 100644 --- a/Include/internal/pycore_typeobject.h +++ b/Include/internal/pycore_typeobject.h @@ -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); diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index c3857195177b..de83b523f986 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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 index 000000000000..52cd45029fb8 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-12-07-13-19-55.gh-issue-112125.4ADN7i.rst @@ -0,0 +1 @@ +Fix None.__ne__(None) returning NotImplemented instead of False diff --git a/Objects/object.c b/Objects/object.c index 8a4010fb1366..aac707d6a26c 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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 */ diff --git a/Objects/typeobject.c b/Objects/typeobject.c index d0c7c5f9439c..71d20687479a 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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) {