[Python-checkins] cpython (2.7): Issue #25455: Clean up reference loops created in tests for recursive

serhiy.storchaka python-checkins at python.org
Sun Jun 12 08:53:31 EDT 2016


https://hg.python.org/cpython/rev/688edc946ab9
changeset:   101945:688edc946ab9
branch:      2.7
parent:      101943:f78be09fbf1a
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Jun 12 15:45:14 2016 +0300
summary:
  Issue #25455: Clean up reference loops created in tests for recursive
functools.partial objects.

files:
  Lib/test/test_functools.py |  33 ++++++++++++++++++-------
  1 files changed, 24 insertions(+), 9 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
@@ -239,21 +239,36 @@
     def test_recursive_pickle(self):
         f = self.partial(capture)
         f.__setstate__((f, (), {}, {}))
-        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
-            with self.assertRaises(RuntimeError):
-                pickle.dumps(f, proto)
+        try:
+            for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+                with self.assertRaises(RuntimeError):
+                    pickle.dumps(f, proto)
+        finally:
+            f.__setstate__((capture, (), {}, {}))
 
         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)
+        try:
+            for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+                f_copy = pickle.loads(pickle.dumps(f, proto))
+                try:
+                    self.assertIs(f_copy.args[0], f_copy)
+                finally:
+                    f_copy.__setstate__((capture, (), {}, {}))
+        finally:
+            f.__setstate__((capture, (), {}, {}))
 
         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)
+        try:
+            for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+                f_copy = pickle.loads(pickle.dumps(f, proto))
+                try:
+                    self.assertIs(f_copy.keywords['a'], f_copy)
+                finally:
+                    f_copy.__setstate__((capture, (), {}, {}))
+        finally:
+            f.__setstate__((capture, (), {}, {}))
 
     # Issue 6083: Reference counting bug
     def test_setstate_refcount(self):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list