Skip to content

Commit

Permalink
Get class and staticmethod from builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran committed Sep 28, 2021
1 parent 40e3df9 commit 4f587cb
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/wrapt/_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,8 @@ static int WraptFunctionWrapper_init(WraptFunctionWrapperObject *self,
static PyObject *classmethod_str = NULL;
static PyObject *staticmethod_str = NULL;
static PyObject *function_str = NULL;
static PyObject *classmethod_type = NULL;
static PyObject *staticmethod_type = NULL;

int result = 0;

Expand All @@ -2664,16 +2666,34 @@ static int WraptFunctionWrapper_init(WraptFunctionWrapperObject *self,
function_str = PyUnicode_InternFromString("function");
}

/* XXX TODO
if (PyObject_IsInstance(wrapped, (PyObject *)&PyClassMethod_Type)) {
if (!classmethod_type) {
PyObject *builtins = PyImport_ImportModule("builtins");
classmethod_type = PyObject_GetAttrString(builtins, "classmethod");
if (!staticmethod_type) {
staticmethod_type = PyObject_GetAttrString(builtins, "staticmethod");
}
Py_DECREF(builtins);
if ((!classmethod_type) || (!staticmethod_type)) {
return -1;
}
}

if (!staticmethod_type) {
PyObject *builtins = PyImport_ImportModule("builtins");
staticmethod_type = PyObject_GetAttrString(builtins, "staticmethod");
Py_DECREF(builtins);
if (!staticmethod_type) {
return -1;
}
}

if (PyObject_IsInstance(wrapped, classmethod_type)) {
binding = classmethod_str;
}
else if (PyObject_IsInstance(wrapped, (PyObject *)&PyStaticMethod_Type)) {
else if (PyObject_IsInstance(wrapped, staticmethod_type)) {
binding = staticmethod_str;
}
else
*/
if ((instance = PyObject_GetAttrString(wrapped, "__self__")) != 0) {
else if ((instance = PyObject_GetAttrString(wrapped, "__self__")) != 0) {
if (PyObject_IsInstance(instance, (PyObject *)&PyType_Type)) {
binding = classmethod_str;
}
Expand Down

0 comments on commit 4f587cb

Please sign in to comment.