]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Weak*Dictionary.update(): Fix calls to [].append() to only have one
authorFred Drake <fdrake@acm.org>
Mon, 16 Apr 2001 17:34:48 +0000 (17:34 +0000)
committerFred Drake <fdrake@acm.org>
Mon, 16 Apr 2001 17:34:48 +0000 (17:34 +0000)
    parameter.

Weak*Dictionary.get():  Make the second parameter optional.

WeakKeyDictionary.has_key(), .keys():  Make these actually work!

Lib/weakref.py

index 6945757b16d09613a6f570c1b2f7d3555e98330f..b6b45282d06582ca7d9cbf49ede1967a1a2b7741 100644 (file)
@@ -54,7 +54,7 @@ class WeakValueDictionary(UserDict.UserDict):
                 new[key] = o
         return new
 
-    def get(self, key, default):
+    def get(self, key, default=None):
         try:
             ref = self.data[key]
         except KeyError:
@@ -100,7 +100,7 @@ class WeakValueDictionary(UserDict.UserDict):
         for key, o in dict.items():
             def remove(o, data=d, key=key):
                 del data[key]
-            L.append(key, ref(o, remove))
+            L.append((key, ref(o, remove)))
         for key, r in L:
             d[key] = r
 
@@ -139,9 +139,12 @@ class WeakKeyDictionary(UserDict.UserDict):
                 new[o] = value
         return new
 
-    def get(self, key, default):
+    def get(self, key, default=None):
         return self.data.get(ref(key),default)
 
+    def has_key(self, key):
+        return self.data.has_key(ref(key))
+
     def items(self):
         L = []
         for key, value in self.data.items():
@@ -150,6 +153,14 @@ class WeakKeyDictionary(UserDict.UserDict):
                 L.append((o, value))
         return L
 
+    def keys(self):
+        L = []
+        for ref in self.data.keys():
+            o = ref()
+            if o is not None:
+                L.append(o)
+        return L
+
     def popitem(self):
         while 1:
             key, value = self.data.popitem()
@@ -164,7 +175,7 @@ class WeakKeyDictionary(UserDict.UserDict):
         d = self.data
         L = []
         for key, value in dict.items():
-            L.append(ref(key, self._remove), value)
+            L.append((ref(key, self._remove), value))
         for key, r in L:
             d[key] = r