| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,14 @@ the definition of all other Python objects. | |||
| 70 | 70 | (((PyObject*)(o))->ob_type) | |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | + .. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type) | ||
| 74 | + | ||
| 75 | + Return non-zero if the object *o* type is *type*. Return zero otherwise. | ||
| 76 | + Equivalent to: ``Py_TYPE(o) == type``. | ||
| 77 | + | ||
| 78 | + .. versionadded:: 3.9 | ||
| 79 | + | ||
| 80 | + | ||
| 73 | 81 | .. c:function:: void Py_SET_TYPE(PyObject *o, PyTypeObject *type) | |
| 74 | 82 | ||
| 75 | 83 | Set the object *o* type to *type*. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ extern "C" { | |||
| 9 | 9 | ||
| 10 | 10 | PyAPI_DATA(PyTypeObject) PyBool_Type; | |
| 11 | 11 | ||
| 12 | - #define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type) | ||
| 12 | + #define PyBool_Check(x) Py_IS_TYPE(x, &PyBool_Type) | ||
| 13 | 13 | ||
| 14 | 14 | /* Py_False and Py_True are the only two bools in existence. | |
| 15 | 15 | Don't forget to apply Py_INCREF() when returning either!!! */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type; | |||
| 24 | 24 | ||
| 25 | 25 | /* Type check macros */ | |
| 26 | 26 | #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type) | |
| 27 | - #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type) | ||
| 27 | + #define PyByteArray_CheckExact(self) Py_IS_TYPE(self, &PyByteArray_Type) | ||
| 28 | 28 | ||
| 29 | 29 | /* Direct API functions */ | |
| 30 | 30 | PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ PyAPI_DATA(PyTypeObject) PyBytesIter_Type; | |||
| 32 | 32 | ||
| 33 | 33 | #define PyBytes_Check(op) \ | |
| 34 | 34 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) | |
| 35 | - #define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type) | ||
| 35 | + #define PyBytes_CheckExact(op) Py_IS_TYPE(op, &PyBytes_Type) | ||
| 36 | 36 | ||
| 37 | 37 | PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); | |
| 38 | 38 | PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ typedef struct { | |||
| 13 | 13 | ||
| 14 | 14 | PyAPI_DATA(PyTypeObject) PyCell_Type; | |
| 15 | 15 | ||
| 16 | - #define PyCell_Check(op) (Py_TYPE(op) == &PyCell_Type) | ||
| 16 | + #define PyCell_Check(op) Py_IS_TYPE(op, &PyCell_Type) | ||
| 17 | 17 | ||
| 18 | 18 | PyAPI_FUNC(PyObject *) PyCell_New(PyObject *); | |
| 19 | 19 | PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,7 +115,7 @@ typedef struct { | |||
| 115 | 115 | ||
| 116 | 116 | PyAPI_DATA(PyTypeObject) PyCode_Type; | |
| 117 | 117 | ||
| 118 | - #define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type) | ||
| 118 | + #define PyCode_Check(op) Py_IS_TYPE(op, &PyCode_Type) | ||
| 119 | 119 | #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars)) | |
| 120 | 120 | ||
| 121 | 121 | /* Public interface */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,7 @@ typedef struct { | |||
| 39 | 39 | PyAPI_DATA(PyTypeObject) PyComplex_Type; | |
| 40 | 40 | ||
| 41 | 41 | #define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type) | |
| 42 | - #define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type) | ||
| 42 | + #define PyComplex_CheckExact(op) Py_IS_TYPE(op, &PyComplex_Type) | ||
| 43 | 43 | ||
| 44 | 44 | #ifndef Py_LIMITED_API | |
| 45 | 45 | PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,9 +17,9 @@ PyAPI_DATA(PyTypeObject) PyContextToken_Type; | |||
| 17 | 17 | typedef struct _pycontexttokenobject PyContextToken; | |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | - #define PyContext_CheckExact(o) (Py_TYPE(o) == &PyContext_Type) | ||
| 21 | - #define PyContextVar_CheckExact(o) (Py_TYPE(o) == &PyContextVar_Type) | ||
| 22 | - #define PyContextToken_CheckExact(o) (Py_TYPE(o) == &PyContextToken_Type) | ||
| 20 | + #define PyContext_CheckExact(o) Py_IS_TYPE(o, &PyContext_Type) | ||
| 21 | + #define PyContextVar_CheckExact(o) Py_IS_TYPE(o, &PyContextVar_Type) | ||
| 22 | + #define PyContextToken_CheckExact(o) Py_IS_TYPE(o, &PyContextToken_Type) | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | PyAPI_FUNC(PyObject *) PyContext_New(void); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -196,19 +196,19 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL; | |||
| 196 | 196 | ||
| 197 | 197 | /* Macros for type checking when not building the Python core. */ | |
| 198 | 198 | #define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType) | |
| 199 | - #define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType) | ||
| 199 | + #define PyDate_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DateType) | ||
| 200 | 200 | ||
| 201 | 201 | #define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType) | |
| 202 | - #define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType) | ||
| 202 | + #define PyDateTime_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DateTimeType) | ||
| 203 | 203 | ||
| 204 | 204 | #define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType) | |
| 205 | - #define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType) | ||
| 205 | + #define PyTime_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->TimeType) | ||
| 206 | 206 | ||
| 207 | 207 | #define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType) | |
| 208 | - #define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType) | ||
| 208 | + #define PyDelta_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DeltaType) | ||
| 209 | 209 | ||
| 210 | 210 | #define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType) | |
| 211 | - #define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType) | ||
| 211 | + #define PyTZInfo_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->TZInfoType) | ||
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | 214 | /* Macros for accessing constructors in a simplified fashion. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ PyAPI_DATA(PyTypeObject) PyDict_Type; | |||
| 16 | 16 | ||
| 17 | 17 | #define PyDict_Check(op) \ | |
| 18 | 18 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) | |
| 19 | - #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) | ||
| 19 | + #define PyDict_CheckExact(op) Py_IS_TYPE(op, &PyDict_Type) | ||
| 20 | 20 | ||
| 21 | 21 | PyAPI_FUNC(PyObject *) PyDict_New(void); | |
| 22 | 22 | PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments