Skip to content

Commit c156300

Browse files
committed
Introduce and use Py_IS_TYPE().
1 parent 96996d7 commit c156300

31 files changed

Lines changed: 66 additions & 51 deletions

Include/boolobject.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
3636

3737
/* Type check macros */
3838
#define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)
39-
#define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)
39+
#define PyByteArray_CheckExact(self) Py_IS_TYPE(self, &PyByteArray_Type)
4040

4141
/* Direct API functions */
4242
PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);

Include/bytesobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
4646

4747
#define PyBytes_Check(op) \
4848
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
49-
#define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type)
49+
#define PyBytes_CheckExact(op) Py_IS_TYPE(op, &PyBytes_Type)
5050

5151
PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
5252
PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);

Include/cellobject.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ typedef struct {
9797

9898
PyAPI_DATA(PyTypeObject) PyCode_Type;
9999

100-
#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
100+
#define PyCode_Check(op) Py_IS_TYPE(op, &PyCode_Type)
101101
#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
102102

103103
/* Public interface */

Include/complexobject.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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(PyContext *) PyContext_New(void);

Include/datetime.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,19 @@ typedef struct {
184184

185185
/* Macros for type checking when building the Python core. */
186186
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
187-
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType)
187+
#define PyDate_CheckExact(op) Py_IS_TYPE(op, &PyDateTime_DateType)
188188

189189
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
190-
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType)
190+
#define PyDateTime_CheckExact(op) Py_IS_TYPE(op, &PyDateTime_DateTimeType)
191191

192192
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
193-
#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType)
193+
#define PyTime_CheckExact(op) Py_IS_TYPE(op, &PyDateTime_TimeType)
194194

195195
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
196-
#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType)
196+
#define PyDelta_CheckExact(op) Py_IS_TYPE(op, &PyDateTime_DeltaType)
197197

198198
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
199-
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType)
199+
#define PyTZInfo_CheckExact(op) Py_IS_TYPE(op, &PyDateTime_TZInfoType)
200200

201201
#else
202202

@@ -211,19 +211,19 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
211211

212212
/* Macros for type checking when not building the Python core. */
213213
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
214-
#define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType)
214+
#define PyDate_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DateType)
215215

216216
#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
217-
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType)
217+
#define PyDateTime_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DateTimeType)
218218

219219
#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
220-
#define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType)
220+
#define PyTime_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->TimeType)
221221

222222
#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
223-
#define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType)
223+
#define PyDelta_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->DeltaType)
224224

225225
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
226-
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType)
226+
#define PyTZInfo_CheckExact(op) Py_IS_TYPE(op, PyDateTimeAPI->TZInfoType)
227227

228228
/* Macros for accessing constructors in a simplified fashion. */
229229
#define PyDate_FromDate(year, month, day) \

Include/dictobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type;
5757

5858
#define PyDict_Check(op) \
5959
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
60-
#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
60+
#define PyDict_CheckExact(op) Py_IS_TYPE(op, &PyDict_Type)
6161
#define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type)
6262
#define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type)
6363
#define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type)

Include/floatobject.h

Lines changed: 1 addition & 1 deletion
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)

0 commit comments

Comments
 (0)