diff options
author | Fred Drake <fdrake@acm.org> | 2001-04-16 17:34:48 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-04-16 17:34:48 (GMT) |
commit | 1d9e4b7de3d15007d5b9e7ac4b38f5e158d3c840 (patch) | |
tree | cbfbd05e3dc6974c0c598adff4b8bf400882ad2a /Lib | |
parent | 67addfe2a87d22458323e268d2bcc7406e6febc2 (diff) | |
download | cpython-1d9e4b7de3d15007d5b9e7ac4b38f5e158d3c840.zip cpython-1d9e4b7de3d15007d5b9e7ac4b38f5e158d3c840.tar.gz cpython-1d9e4b7de3d15007d5b9e7ac4b38f5e158d3c840.tar.bz2 |
Weak*Dictionary.update(): Fix calls to [].append() to only have one
parameter.
Weak*Dictionary.get(): Make the second parameter optional.
WeakKeyDictionary.has_key(), .keys(): Make these actually work!
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/weakref.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index 6945757..b6b4528 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -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 |