Commit 46fe29de authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #25455: Clean up reference loops created in tests for recursive

functools.partial objects.
parent 7bea2347
...@@ -225,15 +225,24 @@ class TestPartialC(TestPartial, unittest.TestCase): ...@@ -225,15 +225,24 @@ class TestPartialC(TestPartial, unittest.TestCase):
f = self.partial(capture) f = self.partial(capture)
f.__setstate__((f, (), {}, {})) f.__setstate__((f, (), {}, {}))
try:
self.assertEqual(repr(f), '%s(%s(...))' % (name, name)) self.assertEqual(repr(f), '%s(%s(...))' % (name, name))
finally:
f.__setstate__((capture, (), {}, {}))
f = self.partial(capture) f = self.partial(capture)
f.__setstate__((capture, (f,), {}, {})) f.__setstate__((capture, (f,), {}, {}))
try:
self.assertEqual(repr(f), '%s(%r, %s(...))' % (name, capture, name)) self.assertEqual(repr(f), '%s(%r, %s(...))' % (name, capture, name))
finally:
f.__setstate__((capture, (), {}, {}))
f = self.partial(capture) f = self.partial(capture)
f.__setstate__((capture, (), {'a': f}, {})) f.__setstate__((capture, (), {'a': f}, {}))
try:
self.assertEqual(repr(f), '%s(%r, a=%s(...))' % (name, capture, name)) self.assertEqual(repr(f), '%s(%r, a=%s(...))' % (name, capture, name))
finally:
f.__setstate__((capture, (), {}, {}))
def test_pickle(self): def test_pickle(self):
f = self.partial(signature, ['asdf'], bar=[True]) f = self.partial(signature, ['asdf'], bar=[True])
...@@ -318,21 +327,36 @@ class TestPartialC(TestPartial, unittest.TestCase): ...@@ -318,21 +327,36 @@ class TestPartialC(TestPartial, unittest.TestCase):
def test_recursive_pickle(self): def test_recursive_pickle(self):
f = self.partial(capture) f = self.partial(capture)
f.__setstate__((f, (), {}, {})) f.__setstate__((f, (), {}, {}))
try:
for proto in range(pickle.HIGHEST_PROTOCOL + 1): for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.assertRaises(RecursionError): with self.assertRaises(RecursionError):
pickle.dumps(f, proto) pickle.dumps(f, proto)
finally:
f.__setstate__((capture, (), {}, {}))
f = self.partial(capture) f = self.partial(capture)
f.__setstate__((capture, (f,), {}, {})) f.__setstate__((capture, (f,), {}, {}))
try:
for proto in range(pickle.HIGHEST_PROTOCOL + 1): for proto in range(pickle.HIGHEST_PROTOCOL + 1):
f_copy = pickle.loads(pickle.dumps(f, proto)) f_copy = pickle.loads(pickle.dumps(f, proto))
try:
self.assertIs(f_copy.args[0], f_copy) self.assertIs(f_copy.args[0], f_copy)
finally:
f_copy.__setstate__((capture, (), {}, {}))
finally:
f.__setstate__((capture, (), {}, {}))
f = self.partial(capture) f = self.partial(capture)
f.__setstate__((capture, (), {'a': f}, {})) f.__setstate__((capture, (), {'a': f}, {}))
try:
for proto in range(pickle.HIGHEST_PROTOCOL + 1): for proto in range(pickle.HIGHEST_PROTOCOL + 1):
f_copy = pickle.loads(pickle.dumps(f, proto)) f_copy = pickle.loads(pickle.dumps(f, proto))
try:
self.assertIs(f_copy.keywords['a'], f_copy) self.assertIs(f_copy.keywords['a'], f_copy)
finally:
f_copy.__setstate__((capture, (), {}, {}))
finally:
f.__setstate__((capture, (), {}, {}))
# Issue 6083: Reference counting bug # Issue 6083: Reference counting bug
def test_setstate_refcount(self): def test_setstate_refcount(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment