Skip to content

Commit d905df7

Browse files
authored
bpo-39573: Add Py_IS_TYPE() function (GH-18488)
Co-Author: Neil Schemenauer <[email protected]>
1 parent 968dcd9 commit d905df7

32 files changed

+61
-46
lines changed

Doc/c-api/structures.rst

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ the definition of all other Python objects.
7070
(((PyObject*)(o))->ob_type)
7171

7272

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+
7381
.. c:function:: void Py_SET_TYPE(PyObject *o, PyTypeObject *type)
7482
7583
Set the object *o* type to *type*.

Include/boolobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C" {
99

1010
PyAPI_DATA(PyTypeObject) PyBool_Type;
1111

12-
#define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type)
12+
#define PyBool_Check(x) Py_IS_TYPE(x, &PyBool_Type)
1313

1414
/* Py_False and Py_True are the only two bools in existence.
1515
Don't forget to apply Py_INCREF() when returning either!!! */

Include/bytearrayobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
2424

2525
/* Type check macros */
2626
#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)
2828

2929
/* Direct API functions */
3030
PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);

Include/bytesobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
3232

3333
#define PyBytes_Check(op) \
3434
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)
3636

3737
PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
3838
PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);

Include/cellobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313

1414
PyAPI_DATA(PyTypeObject) PyCell_Type;
1515

16-
#define PyCell_Check(op) (Py_TYPE(op) == &PyCell_Type)
16+
#define PyCell_Check(op) Py_IS_TYPE(op, &PyCell_Type)
1717

1818
PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
1919
PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);

Include/code.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef struct {
115115

116116
PyAPI_DATA(PyTypeObject) PyCode_Type;
117117

118-
#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
118+
#define PyCode_Check(op) Py_IS_TYPE(op, &PyCode_Type)
119119
#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
120120

121121
/* Public interface */

Include/complexobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct {
3939
PyAPI_DATA(PyTypeObject) PyComplex_Type;
4040

4141
#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)
4343

4444
#ifndef Py_LIMITED_API
4545
PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);

Include/context.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ PyAPI_DATA(PyTypeObject) PyContextToken_Type;
1717
typedef struct _pycontexttokenobject PyContextToken;
1818

1919

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)
2323

2424

2525
PyAPI_FUNC(PyObject *) PyContext_New(void);

Include/datetime.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,19 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
196196

197197
/* Macros for type checking when not building the Python core. */
198198
#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)
200200

201201
#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)
203203

204204
#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)
206206

207207
#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)
209209

210210
#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)
212212

213213

214214
/* Macros for accessing constructors in a simplified fashion. */

Include/dictobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PyAPI_DATA(PyTypeObject) PyDict_Type;
1616

1717
#define PyDict_Check(op) \
1818
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)
2020

2121
PyAPI_FUNC(PyObject *) PyDict_New(void);
2222
PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);

Include/floatobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct {
2121
PyAPI_DATA(PyTypeObject) PyFloat_Type;
2222

2323
#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)
2525

2626
#ifdef Py_NAN
2727
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)

Include/funcobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct {
4343

4444
PyAPI_DATA(PyTypeObject) PyFunction_Type;
4545

46-
#define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type)
46+
#define PyFunction_Check(op) Py_IS_TYPE(op, &PyFunction_Type)
4747

4848
PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
4949
PyAPI_FUNC(PyObject *) PyFunction_NewWithQualName(PyObject *, PyObject *, PyObject *);

Include/genobject.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct {
3838
PyAPI_DATA(PyTypeObject) PyGen_Type;
3939

4040
#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)
4242

4343
PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
4444
PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *,
@@ -58,7 +58,7 @@ typedef struct {
5858
PyAPI_DATA(PyTypeObject) PyCoro_Type;
5959
PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
6060

61-
#define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type)
61+
#define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type)
6262
PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
6363
PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *,
6464
PyObject *name, PyObject *qualname);
@@ -89,7 +89,7 @@ PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
8989
PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *,
9090
PyObject *name, PyObject *qualname);
9191

92-
#define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type)
92+
#define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type)
9393

9494
PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
9595

Include/internal/pycore_hamt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define _Py_HAMT_MAX_TREE_DEPTH 7
99

1010

11-
#define PyHamt_Check(o) (Py_TYPE(o) == &_PyHamt_Type)
11+
#define PyHamt_Check(o) Py_IS_TYPE(o, &_PyHamt_Type)
1212

1313

1414
/* Abstract tree node. */

Include/iterobject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ extern "C" {
88
PyAPI_DATA(PyTypeObject) PySeqIter_Type;
99
PyAPI_DATA(PyTypeObject) PyCallIter_Type;
1010

11-
#define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type)
11+
#define PySeqIter_Check(op) Py_IS_TYPE(op, &PySeqIter_Type)
1212

1313
PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
1414

1515

16-
#define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type)
16+
#define PyCallIter_Check(op) Py_IS_TYPE(op, &PyCallIter_Type)
1717

1818
PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
1919

Include/listobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
2323

2424
#define PyList_Check(op) \
2525
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)
2727

2828
PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
2929
PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);

Include/memoryobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
1111
#endif
1212
PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
1313

14-
#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
14+
#define PyMemoryView_Check(op) Py_IS_TYPE(op, &PyMemoryView_Type)
1515

1616
#ifndef Py_LIMITED_API
1717
/* Get a pointer to the memoryview's private copy of the exporter's buffer. */

Include/methodobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313

1414
PyAPI_DATA(PyTypeObject) PyCFunction_Type;
1515

16-
#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)
16+
#define PyCFunction_Check(op) Py_IS_TYPE(op, &PyCFunction_Type)
1717

1818
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
1919
typedef PyObject *(*_PyCFunctionFast) (PyObject *, PyObject *const *, Py_ssize_t);

Include/moduleobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010
PyAPI_DATA(PyTypeObject) PyModule_Type;
1111

1212
#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)
1414

1515
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
1616
PyAPI_FUNC(PyObject *) PyModule_NewObject(

Include/object.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ typedef struct {
123123
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
124124
#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
125125

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+
126131
static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
127132
ob->ob_refcnt = refcnt;
128133
}
@@ -211,7 +216,7 @@ PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
211216
/* Generic type check */
212217
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
213218
#define PyObject_TypeCheck(ob, tp) \
214-
(Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
219+
(Py_IS_TYPE(ob, tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
215220

216221
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
217222
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
@@ -623,7 +628,7 @@ static inline int _PyType_Check(PyObject *op) {
623628
#define PyType_Check(op) _PyType_Check(_PyObject_CAST(op))
624629

625630
static inline int _PyType_CheckExact(PyObject *op) {
626-
return (Py_TYPE(op) == &PyType_Type);
631+
return Py_IS_TYPE(op, &PyType_Type);
627632
}
628633
#define PyType_CheckExact(op) _PyType_CheckExact(_PyObject_CAST(op))
629634

Include/odictobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ PyAPI_DATA(PyTypeObject) PyODictItems_Type;
1919
PyAPI_DATA(PyTypeObject) PyODictValues_Type;
2020

2121
#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)
2323
#define PyODict_SIZE(op) PyDict_GET_SIZE((op))
2424

2525
PyAPI_FUNC(PyObject *) PyODict_New(void);

Include/pycapsule.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PyAPI_DATA(PyTypeObject) PyCapsule_Type;
2222

2323
typedef void (*PyCapsule_Destructor)(PyObject *);
2424

25-
#define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type)
25+
#define PyCapsule_CheckExact(op) Py_IS_TYPE(op, &PyCapsule_Type)
2626

2727

2828
PyAPI_FUNC(PyObject *) PyCapsule_New(

Include/rangeobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ PyAPI_DATA(PyTypeObject) PyRange_Type;
1919
PyAPI_DATA(PyTypeObject) PyRangeIter_Type;
2020
PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type;
2121

22-
#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type)
22+
#define PyRange_Check(op) Py_IS_TYPE(op, &PyRange_Type)
2323

2424
#ifdef __cplusplus
2525
}

Include/setobject.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
8888
PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
8989
PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);
9090

91-
#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type)
91+
#define PyFrozenSet_CheckExact(ob) Py_IS_TYPE(ob, &PyFrozenSet_Type)
9292
#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))
9494
#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) || \
9696
PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \
9797
PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
9898
#define PySet_Check(ob) \
99-
(Py_TYPE(ob) == &PySet_Type || \
99+
(Py_IS_TYPE(ob, &PySet_Type) || \
100100
PyType_IsSubtype(Py_TYPE(ob), &PySet_Type))
101101
#define PyFrozenSet_Check(ob) \
102-
(Py_TYPE(ob) == &PyFrozenSet_Type || \
102+
(Py_IS_TYPE(ob, &PyFrozenSet_Type) || \
103103
PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
104104

105105
#ifdef __cplusplus

Include/sliceobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct {
2828
PyAPI_DATA(PyTypeObject) PySlice_Type;
2929
PyAPI_DATA(PyTypeObject) PyEllipsis_Type;
3030

31-
#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type)
31+
#define PySlice_Check(op) Py_IS_TYPE(op, &PySlice_Type)
3232

3333
PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
3434
PyObject* step);

Include/symtable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef struct _symtable_entry {
6969

7070
PyAPI_DATA(PyTypeObject) PySTEntry_Type;
7171

72-
#define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type)
72+
#define PySTEntry_Check(op) Py_IS_TYPE(op, &PySTEntry_Type)
7373

7474
PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
7575

Include/traceback.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
1313

1414
/* Reveal traceback type so we can typecheck traceback objects */
1515
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)
1717

1818

1919
#ifndef Py_LIMITED_API

Include/tupleobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ PyAPI_DATA(PyTypeObject) PyTupleIter_Type;
2525

2626
#define PyTuple_Check(op) \
2727
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)
2929

3030
PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
3131
PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);

Include/unicodeobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
113113

114114
#define PyUnicode_Check(op) \
115115
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)
117117

118118
/* --- Constants ---------------------------------------------------------- */
119119

Include/weakrefobject.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;
4646

4747
#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)
4848
#define PyWeakref_CheckRefExact(op) \
49-
(Py_TYPE(op) == &_PyWeakref_RefType)
49+
Py_IS_TYPE(op, &_PyWeakref_RefType)
5050
#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))
5353

5454
#define PyWeakref_Check(op) \
5555
(PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
Original file line numberDiff line numberDiff 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*.

Objects/genobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
255255
if (PyCoro_CheckExact(gen)) {
256256
msg = "coroutine raised StopIteration";
257257
}
258-
else if PyAsyncGen_CheckExact(gen) {
258+
else if (PyAsyncGen_CheckExact(gen)) {
259259
msg = "async generator raised StopIteration";
260260
}
261261
_PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);

0 commit comments

Comments
 (0)