mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
6e468cb16b
commit
09bbebea16
9 changed files with 198 additions and 38 deletions
|
@ -122,6 +122,11 @@ typedef struct {
|
|||
#define _PyVarObject_CAST_CONST(op) ((const PyVarObject*)(op))
|
||||
|
||||
|
||||
// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
|
||||
PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
|
||||
#define Py_Is(x, y) ((x) == (y))
|
||||
|
||||
|
||||
static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
|
||||
return ob->ob_refcnt;
|
||||
}
|
||||
|
@ -586,6 +591,10 @@ Don't forget to apply Py_INCREF() when returning this value!!!
|
|||
PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
|
||||
#define Py_None (&_Py_NoneStruct)
|
||||
|
||||
// Test if an object is the None singleton, the same as "x is None" in Python.
|
||||
PyAPI_FUNC(int) Py_IsNone(PyObject *x);
|
||||
#define Py_IsNone(x) Py_Is((x), Py_None)
|
||||
|
||||
/* Macro for returning Py_None from a function */
|
||||
#define Py_RETURN_NONE return Py_NewRef(Py_None)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue