]> granicus.if.org Git - python/commitdiff
WeakDictionary.items(): Do not allow (key,ref) pairs to leak out for
authorFred Drake <fdrake@acm.org>
Fri, 2 Feb 2001 15:13:24 +0000 (15:13 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 2 Feb 2001 15:13:24 +0000 (15:13 +0000)
    dead references.

Lib/weakref.py

index f6e07c91acc8f7227ba7ffde743f98609a3b6ed7..cc7b494c913ce7ce5186f7550889fda745b19375 100644 (file)
@@ -67,12 +67,12 @@ class WeakDictionary(UserDict.UserDict):
                 return o
 
     def items(self):
-        L = self.data.items()
-        for i in range(len(L)):
+        L = []
+        for key, ref in self.data.items():
             key, ref = L[i]
             o = ref()
             if o is not None:
-                L[i] = key, o
+                L.append((key, o))
         return L
 
     def popitem(self):