summaryrefslogtreecommitdiffstats
path: root/Modules/_functoolsmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-06-08 08:19:24 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-06-08 08:19:24 (GMT)
commite7070f09bcbc4aa960216d099beff4431744a7e2 (patch)
tree0959f5c789d72922945ae6e250845585d64e840c /Modules/_functoolsmodule.c
parent77cb197aaa289d1815b9b476f48ebe86d9b75a72 (diff)
downloadcpython-e7070f09bcbc4aa960216d099beff4431744a7e2.zip
cpython-e7070f09bcbc4aa960216d099beff4431744a7e2.tar.gz
cpython-e7070f09bcbc4aa960216d099beff4431744a7e2.tar.bz2
Issue #14373: C implementation of functools.lru_cache() now can be used with
methods.
Diffstat (limited to 'Modules/_functoolsmodule.c')
-rw-r--r--Modules/_functoolsmodule.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 99b50b0..95b5b13 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -1004,6 +1004,16 @@ lru_cache_call(lru_cache_object *self, PyObject *args, PyObject *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)
{
return PyObject_CallFunction(self->cache_info_type, "nnOn",
@@ -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 */