Skip to content

Commit e6d28a1

Browse files
bpo-44378: Fix a compiler warning in Py_IS_TYPE() (GH-26644)
Py_IS_TYPE() no longer uses Py_TYPE() to avoid a compiler warning: no longer cast "const PyObject*" to "PyObject*". (cherry picked from commit 304dfec) Co-authored-by: Victor Stinner <[email protected]>
1 parent d7930fb commit e6d28a1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Include/object.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ static inline Py_ssize_t _Py_REFCNT(const PyObject *ob) {
141141

142142

143143
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
144-
return Py_TYPE(ob) == type;
144+
// bpo-44378: Don't use Py_TYPE() since Py_TYPE() requires a non-const
145+
// object.
146+
return ob->ob_type == type;
145147
}
146148
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)
147149

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:c:func:`Py_IS_TYPE` no longer uses :c:func:`Py_TYPE` to avoid a compiler
2+
warning: no longer cast ``const PyObject*`` to ``PyObject*``.
3+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)