mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Marc-Andre Lemburg's patch to support instance methods with other
callable objects than regular Pythonm functions as their im_func.
This commit is contained in:
parent
bb71ab68f9
commit
7859f87fdb
3 changed files with 41 additions and 19 deletions
|
@ -71,11 +71,23 @@ new_instancemethod(unused, args)
|
|||
PyObject* self;
|
||||
PyObject* classObj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!",
|
||||
&PyFunction_Type, &func,
|
||||
&PyInstance_Type, &self,
|
||||
if (!PyArg_ParseTuple(args, "OOO!",
|
||||
&func,
|
||||
&self,
|
||||
&PyClass_Type, &classObj))
|
||||
return NULL;
|
||||
if (!PyCallable_Check(func)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"first argument must be callable");
|
||||
return NULL;
|
||||
}
|
||||
if (self == Py_None)
|
||||
self = NULL;
|
||||
else if (!PyInstance_Check(self)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"second argument must be instance or None");
|
||||
return NULL;
|
||||
}
|
||||
return PyMethod_New(func, self, classObj);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue