Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit be718c3

Browse files
jdemeyerencukou
authored andcommitted
bpo-36974: add some assertions for PEP 590 (pythonGH-13682)
1 parent 9e3e06e commit be718c3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Objects/typeobject.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5233,6 +5233,20 @@ PyType_Ready(PyTypeObject *type)
52335233
_PyObject_ASSERT((PyObject *)type,
52345234
(type->tp_flags & Py_TPFLAGS_READYING) == 0);
52355235

5236+
/* Consistency checks for PEP 590:
5237+
* - Py_TPFLAGS_METHOD_DESCRIPTOR requires tp_descr_get
5238+
* - _Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and
5239+
* tp_vectorcall_offset > 0
5240+
* To avoid mistakes, we require this before inheriting.
5241+
*/
5242+
if (type->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) {
5243+
_PyObject_ASSERT((PyObject *)type, type->tp_descr_get != NULL);
5244+
}
5245+
if (type->tp_flags & _Py_TPFLAGS_HAVE_VECTORCALL) {
5246+
_PyObject_ASSERT((PyObject *)type, type->tp_vectorcall_offset > 0);
5247+
_PyObject_ASSERT((PyObject *)type, type->tp_call != NULL);
5248+
}
5249+
52365250
type->tp_flags |= Py_TPFLAGS_READYING;
52375251

52385252
#ifdef Py_TRACE_REFS

0 commit comments

Comments
 (0)