[Python-checkins] cpython (3.5): Issue #25447: Copying the lru_cache() wrapper object now always works,
serhiy.storchaka
python-checkins at python.org
Mon Dec 28 17:01:52 EST 2015
https://hg.python.org/cpython/rev/33b428ef34b9
changeset: 99697:33b428ef34b9
branch: 3.5
parent: 99693:003f1f60a09c
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Dec 28 23:58:07 2015 +0200
summary:
Issue #25447: Copying the lru_cache() wrapper object now always works,
independedly from the type of the wrapped object (by returning the original
object unchanged).
files:
Lib/test/test_functools.py | 14 ++++++++++++--
Misc/NEWS | 4 ++++
Modules/_functoolsmodule.c | 16 ++++++++++++++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1262,14 +1262,24 @@
def test_copy(self):
cls = self.__class__
- for f in cls.cached_func[0], cls.cached_meth, cls.cached_staticmeth:
+ def orig(x, y):
+ return 3 * x + y
+ part = self.module.partial(orig, 2)
+ funcs = (cls.cached_func[0], cls.cached_meth, cls.cached_staticmeth,
+ self.module.lru_cache(2)(part))
+ for f in funcs:
with self.subTest(func=f):
f_copy = copy.copy(f)
self.assertIs(f_copy, f)
def test_deepcopy(self):
cls = self.__class__
- for f in cls.cached_func[0], cls.cached_meth, cls.cached_staticmeth:
+ def orig(x, y):
+ return 3 * x + y
+ part = self.module.partial(orig, 2)
+ funcs = (cls.cached_func[0], cls.cached_meth, cls.cached_staticmeth,
+ self.module.lru_cache(2)(part))
+ for f in funcs:
with self.subTest(func=f):
f_copy = copy.deepcopy(f)
self.assertIs(f_copy, f)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,10 @@
Library
-------
+- Issue #25447: Copying the lru_cache() wrapper object now always works,
+ independedly from the type of the wrapped object (by returning the original
+ object unchanged).
+
- Issue #24103: Fixed possible use after free in ElementTree.XMLPullParser.
- Issue #25860: os.fwalk() no longer skips remaining directories when error
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -1053,6 +1053,20 @@
return PyObject_GetAttrString(self, "__qualname__");
}
+static PyObject *
+lru_cache_copy(PyObject *self, PyObject *unused)
+{
+ Py_INCREF(self);
+ return self;
+}
+
+static PyObject *
+lru_cache_deepcopy(PyObject *self, PyObject *unused)
+{
+ Py_INCREF(self);
+ return self;
+}
+
static int
lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg)
{
@@ -1104,6 +1118,8 @@
{"cache_info", (PyCFunction)lru_cache_cache_info, METH_NOARGS},
{"cache_clear", (PyCFunction)lru_cache_cache_clear, METH_NOARGS},
{"__reduce__", (PyCFunction)lru_cache_reduce, METH_NOARGS},
+ {"__copy__", (PyCFunction)lru_cache_copy, METH_VARARGS},
+ {"__deepcopy__", (PyCFunction)lru_cache_deepcopy, METH_VARARGS},
{NULL}
};
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list