summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-12 08:51:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-12 08:51:26 (GMT)
commitb62ff6eb577fe1cbacc4b2a8def78ba3e58c34dd (patch)
tree3c46e17f35de3fb309bd1f5671f85a7b539d16a0 /Lib/test/test_functools.py
parentc3905442995d620b4d2b9fa0587772fc65a10154 (diff)
parent179f960d47dc9f2c18e5b535db63fb70b21fc3ea (diff)
downloadcpython-b62ff6eb577fe1cbacc4b2a8def78ba3e58c34dd.zip
cpython-b62ff6eb577fe1cbacc4b2a8def78ba3e58c34dd.tar.gz
cpython-b62ff6eb577fe1cbacc4b2a8def78ba3e58c34dd.tar.bz2
Issue #25455: Fixed a crash in repr of recursive functools.partial objects.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 852173c..03e7e5b 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -217,6 +217,24 @@ class TestPartialC(TestPartial, unittest.TestCase):
['{}({!r}, {}, {})'.format(name, capture, args_repr, kwargs_repr)
for kwargs_repr in kwargs_reprs])
+ def test_recursive_repr(self):
+ if self.partial is c_functools.partial:
+ name = 'functools.partial'
+ else:
+ name = self.partial.__name__
+
+ f = self.partial(capture)
+ f.__setstate__((f, (), {}, {}))
+ self.assertEqual(repr(f), '%s(%s(...))' % (name, name))
+
+ f = self.partial(capture)
+ f.__setstate__((capture, (f,), {}, {}))
+ self.assertEqual(repr(f), '%s(%r, %s(...))' % (name, capture, name))
+
+ f = self.partial(capture)
+ f.__setstate__((capture, (), {'a': f}, {}))
+ self.assertEqual(repr(f), '%s(%r, a=%s(...))' % (name, capture, name))
+
def test_pickle(self):
f = self.partial(signature, ['asdf'], bar=[True])
f.attr = []
@@ -297,6 +315,25 @@ class TestPartialC(TestPartial, unittest.TestCase):
self.assertEqual(r, ((1, 2), {}))
self.assertIs(type(r[0]), tuple)
+ def test_recursive_pickle(self):
+ f = self.partial(capture)
+ f.__setstate__((f, (), {}, {}))
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ with self.assertRaises(RecursionError):
+ pickle.dumps(f, proto)
+
+ f = self.partial(capture)
+ f.__setstate__((capture, (f,), {}, {}))
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ f_copy = pickle.loads(pickle.dumps(f, proto))
+ self.assertIs(f_copy.args[0], f_copy)
+
+ f = self.partial(capture)
+ f.__setstate__((capture, (), {'a': f}, {}))
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ f_copy = pickle.loads(pickle.dumps(f, proto))
+ self.assertIs(f_copy.keywords['a'], f_copy)
+
# Issue 6083: Reference counting bug
def test_setstate_refcount(self):
class BadSequence: