[Python-checkins] cpython (merge 3.3 -> default): Issue #20006: Fix sporadic failures in test_weakset.

antoine.pitrou python-checkins at python.org
Wed Dec 18 00:32:13 CET 2013


http://hg.python.org/cpython/rev/26d92a21f6cf
changeset:   88035:26d92a21f6cf
parent:      88031:d032245a122c
parent:      88034:a3d86f80c899
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Wed Dec 18 00:32:02 2013 +0100
summary:
  Issue #20006: Fix sporadic failures in test_weakset.

files:
  Lib/_weakrefset.py       |  2 ++
  Lib/test/test_weakset.py |  8 ++++++--
  2 files changed, 8 insertions(+), 2 deletions(-)


diff --git a/Lib/_weakrefset.py b/Lib/_weakrefset.py
--- a/Lib/_weakrefset.py
+++ b/Lib/_weakrefset.py
@@ -60,6 +60,8 @@
             for itemref in self.data:
                 item = itemref()
                 if item is not None:
+                    # Caveat: the iterator will keep a strong reference to
+                    # `item` until it is resumed or closed.
                     yield item
 
     def __len__(self):
diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py
--- a/Lib/test/test_weakset.py
+++ b/Lib/test/test_weakset.py
@@ -370,10 +370,14 @@
         def testcontext():
             try:
                 it = iter(s)
-                next(it)
-                del it
+                # Start iterator
+                yielded = ustr(str(next(it)))
                 # Schedule an item for removal and recreate it
                 u = ustr(str(items.pop()))
+                if yielded == u:
+                    # The iterator still has a reference to the removed item,
+                    # advance it (issue #20006).
+                    next(it)
                 gc.collect()      # just in case
                 yield u
             finally:

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


More information about the Python-checkins mailing list