[issue21321] itertools.islice() doesn't release reference to the source iterator when the slice is exhausted

Antoine Pitrou report at bugs.python.org
Mon Apr 28 21:54:56 CEST 2014


Antoine Pitrou added the comment:

Anton, the test is wrong: it is taking a reference to the iterable object (the list), not the iterator.

To check the reference to the original iterator is released, something like this would work:

>>> import itertools, weakref
>>> it = (x for x in (1, 2))
>>> wr = weakref.ref(it)
>>> it = itertools.islice(it, 1)
>>> wr() is None
False
>>> list(it)
[1]
>>> wr() is None  # returns True with the patch, False without
True

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21321>
_______________________________________


More information about the Python-bugs-list mailing list