diff options
author | Jeroen Demeyer <J.Demeyer@UGent.be> | 2019-06-02 23:57:22 (GMT) |
---|---|---|
committer | Petr Viktorin <encukou@gmail.com> | 2019-06-02 23:57:22 (GMT) |
commit | be718c33f06b3496faa61142df24fb071fd5d1f1 (patch) | |
tree | 4bc82e6dd865af8b38f066cc4b3d94220494679f /Objects | |
parent | 9e3e06e582accec82eb29cf665c3b4c7d84d2eb0 (diff) | |
download | cpython-be718c33f06b3496faa61142df24fb071fd5d1f1.zip cpython-be718c33f06b3496faa61142df24fb071fd5d1f1.tar.gz cpython-be718c33f06b3496faa61142df24fb071fd5d1f1.tar.bz2 |
bpo-36974: add some assertions for PEP 590 (GH-13682)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index beb0ddd..006df8d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5233,6 +5233,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 |