summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_functoolsmodule.c3
-rw-r--r--Modules/_testcapimodule.c57
2 files changed, 59 insertions, 1 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index dcc9129..13f2db9 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -1333,7 +1333,8 @@ static PyTypeObject lru_cache_type = {
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR,
/* tp_flags */
lru_cache_doc, /* tp_doc */
(traverseproc)lru_cache_tp_traverse,/* tp_traverse */
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 51e5d80..8ba9270 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5787,6 +5787,46 @@ static PyTypeObject Generic_Type = {
};
+/* Test PEP 590 */
+
+static PyObject *
+func_descr_get(PyObject *func, PyObject *obj, PyObject *type)
+{
+ if (obj == Py_None || obj == NULL) {
+ Py_INCREF(func);
+ return func;
+ }
+ return PyMethod_New(func, obj);
+}
+
+static PyObject *
+nop_descr_get(PyObject *func, PyObject *obj, PyObject *type)
+{
+ Py_INCREF(func);
+ return func;
+}
+
+static PyTypeObject MethodDescriptorBase_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "MethodDescriptorBase",
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_METHOD_DESCRIPTOR,
+ .tp_descr_get = func_descr_get,
+};
+
+static PyTypeObject MethodDescriptorDerived_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "MethodDescriptorDerived",
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+};
+
+static PyTypeObject MethodDescriptorNopGet_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "MethodDescriptorNopGet",
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_descr_get = nop_descr_get,
+};
+
+
static struct PyModuleDef _testcapimodule = {
PyModuleDef_HEAD_INIT,
"_testcapi",
@@ -5834,6 +5874,23 @@ PyInit__testcapi(void)
Py_INCREF(&MyList_Type);
PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type);
+ if (PyType_Ready(&MethodDescriptorBase_Type) < 0)
+ return NULL;
+ Py_INCREF(&MethodDescriptorBase_Type);
+ PyModule_AddObject(m, "MethodDescriptorBase", (PyObject *)&MethodDescriptorBase_Type);
+
+ MethodDescriptorDerived_Type.tp_base = &MethodDescriptorBase_Type;
+ if (PyType_Ready(&MethodDescriptorDerived_Type) < 0)
+ return NULL;
+ Py_INCREF(&MethodDescriptorDerived_Type);
+ PyModule_AddObject(m, "MethodDescriptorDerived", (PyObject *)&MethodDescriptorDerived_Type);
+
+ MethodDescriptorNopGet_Type.tp_base = &MethodDescriptorBase_Type;
+ if (PyType_Ready(&MethodDescriptorNopGet_Type) < 0)
+ return NULL;
+ Py_INCREF(&MethodDescriptorNopGet_Type);
+ PyModule_AddObject(m, "MethodDescriptorNopGet", (PyObject *)&MethodDescriptorNopGet_Type);
+
if (PyType_Ready(&GenericAlias_Type) < 0)
return NULL;
Py_INCREF(&GenericAlias_Type);