From e7070f09bcbc4aa960216d099beff4431744a7e2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 8 Jun 2015 11:19:24 +0300 Subject: Issue #14373: C implementation of functools.lru_cache() now can be used with methods. --- Modules/_functoolsmodule.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Modules/_functoolsmodule.c') diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 99b50b0e9d..95b5b13fbe 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -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 */ -- cgit v1.2.1