Commit 320b3915 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #20006: Fix sporadic failures in test_weakset.

parent 0c73fc04
......@@ -60,6 +60,8 @@ class WeakSet:
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):
......
......@@ -370,9 +370,14 @@ class TestWeakSet(unittest.TestCase):
def testcontext():
try:
it = iter(s)
next(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:
......
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