summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-06-04 15:54:14 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-06-04 15:54:37 +0200
commit09979e15c1e619f278b78d7de1ed077d346842a6 (patch)
tree050e1ea9fa39d5d658eaf8d9bfb7d86e2ee29bda
parent8359cf76506610b1e3c552f2012f6657c57fb489 (diff)
downloadcython-09979e15c1e619f278b78d7de1ed077d346842a6.tar.gz
Simplify classmethod() code in Py3 where "PyMethodDescr_Type" is directly available.
-rw-r--r--Cython/Utility/CythonFunction.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c
index 118333c03..a65c8eee3 100644
--- a/Cython/Utility/CythonFunction.c
+++ b/Cython/Utility/CythonFunction.c
@@ -1292,7 +1292,8 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
// special C-API function only in Pyston and PyPy >= 5.9
if (PyMethodDescr_Check(method))
#else
- // It appears that PyMethodDescr_Type is not exposed anywhere in the CPython C-API
+ #if PY_MAJOR_VERSION == 2
+ // PyMethodDescr_Type is not exposed in the CPython C-API in Py2.
static PyTypeObject *methoddescr_type = NULL;
if (methoddescr_type == NULL) {
PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append");
@@ -1300,6 +1301,9 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
methoddescr_type = Py_TYPE(meth);
Py_DECREF(meth);
}
+ #else
+ PyTypeObject *methoddescr_type = &PyMethodDescr_Type;
+ #endif
if (__Pyx_TypeCheck(method, methoddescr_type))
#endif
{