Issue #14373: C implementation of functools.lru_cache() now can be used with

methods.
This commit is contained in:
Serhiy Storchaka 2015-06-08 11:19:24 +03:00
parent 77cb197aaa
commit e7070f09bc
3 changed files with 45 additions and 1 deletions

View file

@ -1003,6 +1003,16 @@ lru_cache_call(lru_cache_object *self, PyObject *args, PyObject *kwds)
return self->wrapper(self, args, kwds);
}
static PyObject *
lru_cache_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
if (obj == Py_None || obj == NULL) {
Py_INCREF(self);
return self;
}
return PyMethod_New(self, obj);
}
static PyObject *
lru_cache_cache_info(lru_cache_object *self, PyObject *unused)
{
@ -1115,7 +1125,7 @@ static PyTypeObject lru_cache_type = {
lru_cache_getsetlist, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
lru_cache_descr_get, /* tp_descr_get */
0, /* tp_descr_set */
offsetof(lru_cache_object, dict), /* tp_dictoffset */
0, /* tp_init */