]> granicus.if.org Git - python/commitdiff
Added a new test for old filter() memory leak
authorBarry Warsaw <barry@python.org>
Thu, 28 Jan 1999 19:44:06 +0000 (19:44 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 28 Jan 1999 19:44:06 +0000 (19:44 +0000)
Lib/test/test_b1.py

index 020c8bce8b97f8f45c3043b8445614991304239c..7155294e8f1d01f57211393625c317d05de531f2 100644 (file)
@@ -184,6 +184,23 @@ if filter(None, Squares(10)) != [1, 4, 9, 16, 25, 36, 49, 64, 81]:
     raise TestFailed, 'filter(None, Squares(10))'
 if filter(lambda x: x%2, Squares(10)) != [1, 9, 25, 49, 81]:
     raise TestFailed, 'filter(oddp, Squares(10))'
+class StrSquares:
+    def __init__(self, max):
+        self.max = max
+        self.sofar = []
+    def __len__(self):
+        return len(self.sofar)
+    def __getitem__(self, i):
+        if not 0 <= i < self.max:
+            raise IndexError
+        n = len(self.sofar)
+        while n <= i:
+            self.sofar.append(str(n*n))
+            n = n+1
+        return self.sofar[i]
+def identity(item):
+    return 1
+filter(identity, Squares(5))
 
 print 'float'
 if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)'