From 66af553f3e7cb1ea310a29970334a0f1e944a308 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Thu, 30 May 2019 17:14:13 +0200 Subject: [PATCH] bpo-36974: add some assertions for PEP 590 --- Objects/typeobject.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index ac5a68681d15d0..5b2740d72a15bb 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5228,6 +5228,20 @@ PyType_Ready(PyTypeObject *type) _PyObject_ASSERT((PyObject *)type, (type->tp_flags & Py_TPFLAGS_READYING) == 0); + /* Consistency checks for PEP 590: + * - Py_TPFLAGS_METHOD_DESCRIPTOR requires tp_descr_get + * - _Py_TPFLAGS_HAVE_VECTORCALL requires tp_call and + * tp_vectorcall_offset > 0 + * To avoid mistakes, we require this before inheriting. + */ + if (type->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR) { + _PyObject_ASSERT((PyObject *)type, type->tp_descr_get != NULL); + } + if (type->tp_flags & _Py_TPFLAGS_HAVE_VECTORCALL) { + _PyObject_ASSERT((PyObject *)type, type->tp_vectorcall_offset > 0); + _PyObject_ASSERT((PyObject *)type, type->tp_call != NULL); + } + type->tp_flags |= Py_TPFLAGS_READYING; #ifdef Py_TRACE_REFS