@@ -5787,6 +5787,46 @@ static PyTypeObject Generic_Type = {
57875787};
57885788
57895789
5790+ /* Test PEP 590 */
5791+
5792+ static PyObject *
5793+ func_descr_get (PyObject * func , PyObject * obj , PyObject * type )
5794+ {
5795+ if (obj == Py_None || obj == NULL ) {
5796+ Py_INCREF (func );
5797+ return func ;
5798+ }
5799+ return PyMethod_New (func , obj );
5800+ }
5801+
5802+ static PyObject *
5803+ nop_descr_get (PyObject * func , PyObject * obj , PyObject * type )
5804+ {
5805+ Py_INCREF (func );
5806+ return func ;
5807+ }
5808+
5809+ static PyTypeObject MethodDescriptorBase_Type = {
5810+ PyVarObject_HEAD_INIT (NULL , 0 )
5811+ "MethodDescriptorBase" ,
5812+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_METHOD_DESCRIPTOR ,
5813+ .tp_descr_get = func_descr_get ,
5814+ };
5815+
5816+ static PyTypeObject MethodDescriptorDerived_Type = {
5817+ PyVarObject_HEAD_INIT (NULL , 0 )
5818+ "MethodDescriptorDerived" ,
5819+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
5820+ };
5821+
5822+ static PyTypeObject MethodDescriptorNopGet_Type = {
5823+ PyVarObject_HEAD_INIT (NULL , 0 )
5824+ "MethodDescriptorNopGet" ,
5825+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
5826+ .tp_descr_get = nop_descr_get ,
5827+ };
5828+
5829+
57905830static struct PyModuleDef _testcapimodule = {
57915831 PyModuleDef_HEAD_INIT ,
57925832 "_testcapi" ,
@@ -5834,6 +5874,23 @@ PyInit__testcapi(void)
58345874 Py_INCREF (& MyList_Type );
58355875 PyModule_AddObject (m , "MyList" , (PyObject * )& MyList_Type );
58365876
5877+ if (PyType_Ready (& MethodDescriptorBase_Type ) < 0 )
5878+ return NULL ;
5879+ Py_INCREF (& MethodDescriptorBase_Type );
5880+ PyModule_AddObject (m , "MethodDescriptorBase" , (PyObject * )& MethodDescriptorBase_Type );
5881+
5882+ MethodDescriptorDerived_Type .tp_base = & MethodDescriptorBase_Type ;
5883+ if (PyType_Ready (& MethodDescriptorDerived_Type ) < 0 )
5884+ return NULL ;
5885+ Py_INCREF (& MethodDescriptorDerived_Type );
5886+ PyModule_AddObject (m , "MethodDescriptorDerived" , (PyObject * )& MethodDescriptorDerived_Type );
5887+
5888+ MethodDescriptorNopGet_Type .tp_base = & MethodDescriptorBase_Type ;
5889+ if (PyType_Ready (& MethodDescriptorNopGet_Type ) < 0 )
5890+ return NULL ;
5891+ Py_INCREF (& MethodDescriptorNopGet_Type );
5892+ PyModule_AddObject (m , "MethodDescriptorNopGet" , (PyObject * )& MethodDescriptorNopGet_Type );
5893+
58375894 if (PyType_Ready (& GenericAlias_Type ) < 0 )
58385895 return NULL ;
58395896 Py_INCREF (& GenericAlias_Type );
0 commit comments