bpo-43753: Add Py_Is() and Py_IsNone() functions (GH-25227)
Add the Py_Is(x, y) function to test if the 'x' object is the 'y'
object, the same as "x is y" in Python. Add also the Py_IsNone(),
Py_IsTrue(), Py_IsFalse() functions to test if an object is,
respectively, the None singleton, the True singleton or the False
singleton.
diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst
index 37072d3..20d5485 100644
--- a/Doc/c-api/structures.rst
+++ b/Doc/c-api/structures.rst
@@ -62,6 +62,37 @@
See documentation of :c:type:`PyVarObject` above.
+.. c:function:: int Py_Is(const PyObject *x, const PyObject *y)
+
+ Test if the *x* object is the *y* object, the same as ``x is y`` in Python.
+
+ .. versionadded:: 3.10
+
+
+.. c:function:: int Py_IsNone(const PyObject *x)
+
+ Test if an object is the ``None`` singleton,
+ the same as ``x is None`` in Python.
+
+ .. versionadded:: 3.10
+
+
+.. c:function:: int Py_IsTrue(const PyObject *x)
+
+ Test if an object is the ``True`` singleton,
+ the same as ``x is True`` in Python.
+
+ .. versionadded:: 3.10
+
+
+.. c:function:: int Py_IsFalse(const PyObject *x)
+
+ Test if an object is the ``False`` singleton,
+ the same as ``x is False`` in Python.
+
+ .. versionadded:: 3.10
+
+
.. c:function:: PyTypeObject* Py_TYPE(const PyObject *o)
Get the type of the Python object *o*.
diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat
index cd9e384..b7e3ef4 100644
--- a/Doc/data/stable_abi.dat
+++ b/Doc/data/stable_abi.dat
@@ -767,7 +767,11 @@
Py_IncRef
Py_Initialize
Py_InitializeEx
+Py_Is
+Py_IsFalse
Py_IsInitialized
+Py_IsNone
+Py_IsTrue
Py_LeaveRecursiveCall
Py_Main
Py_MakePendingCalls
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 7cf5576..18d83b6 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -1385,6 +1385,13 @@
build (``Py_TRACE_REFS`` macro).
(Contributed by Victor Stinner in :issue:`43688`.)
+* Add the :c:func:`Py_Is(x, y) <Py_Is>` function to test if the *x* object is
+ the *y* object, the same as ``x is y`` in Python. Add also the
+ :c:func:`Py_IsNone`, :c:func:`Py_IsTrue`, :c:func:`Py_IsFalse` functions to
+ test if an object is, respectively, the ``None`` singleton, the ``True``
+ singleton or the ``False`` singleton.
+ (Contributed by Victor Stinner in :issue:`43753`.)
+
Porting to Python 3.10
----------------------