bpo-39573: Add Py_IS_TYPE() function (GH-18488) · python/cpython@d905df7 (original) (raw)
32 files changed
lines changed
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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,7 +21,7 @@ typedef struct { | ||
21 | 21 | PyAPI_DATA(PyTypeObject) PyFloat_Type; |
22 | 22 | |
23 | 23 | #define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type) |
24 | -#define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type) | |
24 | +#define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type) | |
25 | 25 | |
26 | 26 | #ifdef Py_NAN |
27 | 27 | #define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -43,7 +43,7 @@ typedef struct { | ||
43 | 43 | |
44 | 44 | PyAPI_DATA(PyTypeObject) PyFunction_Type; |
45 | 45 | |
46 | -#define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type) | |
46 | +#define PyFunction_Check(op) Py_IS_TYPE(op, &PyFunction_Type) | |
47 | 47 | |
48 | 48 | PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *); |
49 | 49 | PyAPI_FUNC(PyObject *) PyFunction_NewWithQualName(PyObject *, PyObject *, PyObject *); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -38,7 +38,7 @@ typedef struct { | ||
38 | 38 | PyAPI_DATA(PyTypeObject) PyGen_Type; |
39 | 39 | |
40 | 40 | #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type) |
41 | -#define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) | |
41 | +#define PyGen_CheckExact(op) Py_IS_TYPE(op, &PyGen_Type) | |
42 | 42 | |
43 | 43 | PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); |
44 | 44 | PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *, |
@@ -58,7 +58,7 @@ typedef struct { | ||
58 | 58 | PyAPI_DATA(PyTypeObject) PyCoro_Type; |
59 | 59 | PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type; |
60 | 60 | |
61 | -#define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type) | |
61 | +#define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type) | |
62 | 62 | PyObject *_PyCoro_GetAwaitableIter(PyObject *o); |
63 | 63 | PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *, |
64 | 64 | PyObject *name, PyObject *qualname); |
@@ -89,7 +89,7 @@ PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type; | ||
89 | 89 | PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *, |
90 | 90 | PyObject *name, PyObject *qualname); |
91 | 91 | |
92 | -#define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type) | |
92 | +#define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type) | |
93 | 93 | |
94 | 94 | PyObject *_PyAsyncGenValueWrapperNew(PyObject *); |
95 | 95 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,7 +8,7 @@ | ||
8 | 8 | #define _Py_HAMT_MAX_TREE_DEPTH 7 |
9 | 9 | |
10 | 10 | |
11 | -#define PyHamt_Check(o) (Py_TYPE(o) == &_PyHamt_Type) | |
11 | +#define PyHamt_Check(o) Py_IS_TYPE(o, &_PyHamt_Type) | |
12 | 12 | |
13 | 13 | |
14 | 14 | /* Abstract tree node. */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,12 +8,12 @@ extern "C" { | ||
8 | 8 | PyAPI_DATA(PyTypeObject) PySeqIter_Type; |
9 | 9 | PyAPI_DATA(PyTypeObject) PyCallIter_Type; |
10 | 10 | |
11 | -#define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type) | |
11 | +#define PySeqIter_Check(op) Py_IS_TYPE(op, &PySeqIter_Type) | |
12 | 12 | |
13 | 13 | PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *); |
14 | 14 | |
15 | 15 | |
16 | -#define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type) | |
16 | +#define PyCallIter_Check(op) Py_IS_TYPE(op, &PyCallIter_Type) | |
17 | 17 | |
18 | 18 | PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *); |
19 | 19 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -23,7 +23,7 @@ PyAPI_DATA(PyTypeObject) PyListRevIter_Type; | ||
23 | 23 | |
24 | 24 | #define PyList_Check(op) \ |
25 | 25 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) |
26 | -#define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type) | |
26 | +#define PyList_CheckExact(op) Py_IS_TYPE(op, &PyList_Type) | |
27 | 27 | |
28 | 28 | PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); |
29 | 29 | PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11,7 +11,7 @@ PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type; | ||
11 | 11 | #endif |
12 | 12 | PyAPI_DATA(PyTypeObject) PyMemoryView_Type; |
13 | 13 | |
14 | -#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) | |
14 | +#define PyMemoryView_Check(op) Py_IS_TYPE(op, &PyMemoryView_Type) | |
15 | 15 | |
16 | 16 | #ifndef Py_LIMITED_API |
17 | 17 | /* Get a pointer to the memoryview's private copy of the exporter's buffer. */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,7 +13,7 @@ extern "C" { | ||
13 | 13 | |
14 | 14 | PyAPI_DATA(PyTypeObject) PyCFunction_Type; |
15 | 15 | |
16 | -#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type) | |
16 | +#define PyCFunction_Check(op) Py_IS_TYPE(op, &PyCFunction_Type) | |
17 | 17 | |
18 | 18 | typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); |
19 | 19 | typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10,7 +10,7 @@ extern "C" { | ||
10 | 10 | PyAPI_DATA(PyTypeObject) PyModule_Type; |
11 | 11 | |
12 | 12 | #define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type) |
13 | -#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type) | |
13 | +#define PyModule_CheckExact(op) Py_IS_TYPE(op, &PyModule_Type) | |
14 | 14 | |
15 | 15 | #if !defined(Py_LIMITED_API) | |
16 | 16 | PyAPI_FUNC(PyObject *) PyModule_NewObject( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -123,6 +123,11 @@ typedef struct { | ||
123 | 123 | #define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type) |
124 | 124 | #define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size) |
125 | 125 | |
126 | +static inline int _Py_IS_TYPE(PyObject *ob, PyTypeObject *type) { | |
127 | +return ob->ob_type == type; | |
128 | +} | |
129 | +#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST(ob), type) | |
130 | + | |
126 | 131 | static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { |
127 | 132 | ob->ob_refcnt = refcnt; |
128 | 133 | } |
@@ -211,7 +216,7 @@ PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int); | ||
211 | 216 | /* Generic type check */ |
212 | 217 | PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *); |
213 | 218 | #define PyObject_TypeCheck(ob, tp) \ |
214 | - (Py_TYPE(ob) == (tp) | | |
219 | + (Py_IS_TYPE(ob, tp) | | |
215 | 220 | |
216 | 221 | PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */ |
217 | 222 | PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ |
@@ -623,7 +628,7 @@ static inline int _PyType_Check(PyObject *op) { | ||
623 | 628 | #define PyType_Check(op) _PyType_Check(_PyObject_CAST(op)) |
624 | 629 | |
625 | 630 | static inline int _PyType_CheckExact(PyObject *op) { |
626 | -return (Py_TYPE(op) == &PyType_Type); | |
631 | +return Py_IS_TYPE(op, &PyType_Type); | |
627 | 632 | } |
628 | 633 | #define PyType_CheckExact(op) _PyType_CheckExact(_PyObject_CAST(op)) |
629 | 634 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,7 +19,7 @@ PyAPI_DATA(PyTypeObject) PyODictItems_Type; | ||
19 | 19 | PyAPI_DATA(PyTypeObject) PyODictValues_Type; |
20 | 20 | |
21 | 21 | #define PyODict_Check(op) PyObject_TypeCheck(op, &PyODict_Type) |
22 | -#define PyODict_CheckExact(op) (Py_TYPE(op) == &PyODict_Type) | |
22 | +#define PyODict_CheckExact(op) Py_IS_TYPE(op, &PyODict_Type) | |
23 | 23 | #define PyODict_SIZE(op) PyDict_GET_SIZE((op)) |
24 | 24 | |
25 | 25 | PyAPI_FUNC(PyObject *) PyODict_New(void); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -22,7 +22,7 @@ PyAPI_DATA(PyTypeObject) PyCapsule_Type; | ||
22 | 22 | |
23 | 23 | typedef void (*PyCapsule_Destructor)(PyObject *); |
24 | 24 | |
25 | -#define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type) | |
25 | +#define PyCapsule_CheckExact(op) Py_IS_TYPE(op, &PyCapsule_Type) | |
26 | 26 | |
27 | 27 | |
28 | 28 | PyAPI_FUNC(PyObject *) PyCapsule_New( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,7 +19,7 @@ PyAPI_DATA(PyTypeObject) PyRange_Type; | ||
19 | 19 | PyAPI_DATA(PyTypeObject) PyRangeIter_Type; |
20 | 20 | PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type; |
21 | 21 | |
22 | -#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type) | |
22 | +#define PyRange_Check(op) Py_IS_TYPE(op, &PyRange_Type) | |
23 | 23 | |
24 | 24 | #ifdef __cplusplus |
25 | 25 | } |
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -88,18 +88,18 @@ PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key); | |||
88 | 88 | PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); | |
89 | 89 | PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset); | |
90 | 90 | ||
91 | -#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type) | ||
91 | +#define PyFrozenSet_CheckExact(ob) Py_IS_TYPE(ob, &PyFrozenSet_Type) | ||
92 | 92 | #define PyAnySet_CheckExact(ob) \ | |
93 | - (Py_TYPE(ob) == &PySet_Type | | Py_TYPE(ob) == &PyFrozenSet_Type) | |
93 | + (Py_IS_TYPE(ob, &PySet_Type) | | Py_IS_TYPE(ob, &PyFrozenSet_Type)) | |
94 | 94 | #define PyAnySet_Check(ob) \ | |
95 | - (Py_TYPE(ob) == &PySet_Type | | Py_TYPE(ob) == &PyFrozenSet_Type | |
95 | + (Py_IS_TYPE(ob, &PySet_Type) | | Py_IS_TYPE(ob, &PyFrozenSet_Type) | |
96 | 96 | PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) | | \ |
97 | 97 | PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) | |
98 | 98 | #define PySet_Check(ob) \ | |
99 | - (Py_TYPE(ob) == &PySet_Type | | \ | |
99 | + (Py_IS_TYPE(ob, &PySet_Type) | | \ | |
100 | 100 | PyType_IsSubtype(Py_TYPE(ob), &PySet_Type)) | |
101 | 101 | #define PyFrozenSet_Check(ob) \ | |
102 | - (Py_TYPE(ob) == &PyFrozenSet_Type | | \ | |
102 | + (Py_IS_TYPE(ob, &PyFrozenSet_Type) | | \ | |
103 | 103 | PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) | |
104 | 104 | ||
105 | 105 | #ifdef __cplusplus |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -28,7 +28,7 @@ typedef struct { | ||
28 | 28 | PyAPI_DATA(PyTypeObject) PySlice_Type; |
29 | 29 | PyAPI_DATA(PyTypeObject) PyEllipsis_Type; |
30 | 30 | |
31 | -#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type) | |
31 | +#define PySlice_Check(op) Py_IS_TYPE(op, &PySlice_Type) | |
32 | 32 | |
33 | 33 | PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop, |
34 | 34 | PyObject* step); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -69,7 +69,7 @@ typedef struct _symtable_entry { | ||
69 | 69 | |
70 | 70 | PyAPI_DATA(PyTypeObject) PySTEntry_Type; |
71 | 71 | |
72 | -#define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type) | |
72 | +#define PySTEntry_Check(op) Py_IS_TYPE(op, &PySTEntry_Type) | |
73 | 73 | |
74 | 74 | PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *); |
75 | 75 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,7 +13,7 @@ PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); | ||
13 | 13 | |
14 | 14 | /* Reveal traceback type so we can typecheck traceback objects */ |
15 | 15 | PyAPI_DATA(PyTypeObject) PyTraceBack_Type; |
16 | -#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type) | |
16 | +#define PyTraceBack_Check(v) Py_IS_TYPE(v, &PyTraceBack_Type) | |
17 | 17 | |
18 | 18 | |
19 | 19 | #ifndef Py_LIMITED_API |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -25,7 +25,7 @@ PyAPI_DATA(PyTypeObject) PyTupleIter_Type; | ||
25 | 25 | |
26 | 26 | #define PyTuple_Check(op) \ |
27 | 27 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) |
28 | -#define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type) | |
28 | +#define PyTuple_CheckExact(op) Py_IS_TYPE(op, &PyTuple_Type) | |
29 | 29 | |
30 | 30 | PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); |
31 | 31 | PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -113,7 +113,7 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; | ||
113 | 113 | |
114 | 114 | #define PyUnicode_Check(op) \ |
115 | 115 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) |
116 | -#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type) | |
116 | +#define PyUnicode_CheckExact(op) Py_IS_TYPE(op, &PyUnicode_Type) | |
117 | 117 | |
118 | 118 | /* --- Constants ---------------------------------------------------------- */ |
119 | 119 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -46,10 +46,10 @@ PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType; | ||
46 | 46 | |
47 | 47 | #define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType) |
48 | 48 | #define PyWeakref_CheckRefExact(op) \ |
49 | -(Py_TYPE(op) == &_PyWeakref_RefType) | |
49 | +Py_IS_TYPE(op, &_PyWeakref_RefType) | |
50 | 50 | #define PyWeakref_CheckProxy(op) \ |
51 | - ((Py_TYPE(op) == &_PyWeakref_ProxyType) | | |
52 | -(Py_TYPE(op) == &_PyWeakref_CallableProxyType)) | |
51 | + (Py_IS_TYPE(op, &_PyWeakref_ProxyType) | | |
52 | +Py_IS_TYPE(op, &_PyWeakref_CallableProxyType)) | |
53 | 53 | |
54 | 54 | #define PyWeakref_Check(op) \ |
55 | 55 | (PyWeakref_CheckRef(op) | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | +Add :c:func:`Py_IS_TYPE` static inline function to check | |
2 | +whether the object *o* type is *type*. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -255,7 +255,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) | ||
255 | 255 | if (PyCoro_CheckExact(gen)) { |
256 | 256 | msg = "coroutine raised StopIteration"; |
257 | 257 | } |
258 | -else if PyAsyncGen_CheckExact(gen) { | |
258 | +else if (PyAsyncGen_CheckExact(gen)) { | |
259 | 259 | msg = "async generator raised StopIteration"; |
260 | 260 | } |
261 | 261 | _PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg); |