diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-29 10:14:47 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-29 10:14:47 (GMT) |
| commit | 32497f89bb6681c5e206c74698cc31c23cfc1b27 (patch) | |
| tree | 1dcfde45fae9c2120fa81aa2abc95a7ba3efed4d /Lib/test | |
| parent | 3f73e4c7150a15ad6756e85c696f77ad14f2f08c (diff) | |
| parent | 26f82efe591a997bcf62111d1776c296f8088623 (diff) | |
| download | cpython-32497f89bb6681c5e206c74698cc31c23cfc1b27.zip cpython-32497f89bb6681c5e206c74698cc31c23cfc1b27.tar.gz cpython-32497f89bb6681c5e206c74698cc31c23cfc1b27.tar.bz2 | |
Issue #21321: itertools.islice() now releases the reference to the source iterator when the slice is exhausted.
Patch by Anton Afanasyev.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_itertools.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 7769f1c..70517f0 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -1,7 +1,7 @@ import unittest from test import support from itertools import * -from weakref import proxy +import weakref from decimal import Decimal from fractions import Fraction import sys @@ -1087,6 +1087,15 @@ class TestBasicOps(unittest.TestCase): list(range(*args))) self.pickletest(islice(range(100), *args)) + # Issue #21321: check source iterator is not referenced + # from islice() after the latter has been exhausted + it = (x for x in (1, 2)) + wr = weakref.ref(it) + it = islice(it, 1) + self.assertIsNotNone(wr()) + list(it) # exhaust the iterator + self.assertIsNone(wr()) + def test_takewhile(self): data = [1, 3, 5, 20, 2, 4, 6, 8] self.assertEqual(list(takewhile(underten, data)), [1, 3, 5]) @@ -1203,7 +1212,7 @@ class TestBasicOps(unittest.TestCase): # test that tee objects are weak referencable a, b = tee(range(10)) - p = proxy(a) + p = weakref.proxy(a) self.assertEqual(getattr(p, '__class__'), type(b)) del a self.assertRaises(ReferenceError, getattr, p, '__class__') |
