File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ def __iter__(self):
6060 for itemref in self .data :
6161 item = itemref ()
6262 if item is not None :
63+ # Caveat: the iterator will keep a strong reference to
64+ # `item` until it is resumed or closed.
6365 yield item
6466
6567 def __len__ (self ):
Original file line number Diff line number Diff line change @@ -370,9 +370,14 @@ def test_weak_destroy_and_mutate_while_iterating(self):
370370 def testcontext ():
371371 try :
372372 it = iter (s )
373- next (it )
373+ # Start iterator
374+ yielded = ustr (str (next (it )))
374375 # Schedule an item for removal and recreate it
375376 u = ustr (str (items .pop ()))
377+ if yielded == u :
378+ # The iterator still has a reference to the removed item,
379+ # advance it (issue #20006).
380+ next (it )
376381 gc .collect () # just in case
377382 yield u
378383 finally :
You can’t perform that action at this time.
0 commit comments