diff options
author | Barry Warsaw <barry@python.org> | 2008-09-04 01:42:51 +0000 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2008-09-04 01:42:51 +0000 |
commit | ecaab837b6ef36edf1840afdba1fbab747c049d7 (patch) | |
tree | 948112c5a3f7dc5e1ee7bc8b473a737328db96ec /Lib/weakref.py | |
parent | 6ecc5c19802b994b3b7033953361f6157b4bdd0d (diff) | |
download | cpython-ecaab837b6ef36edf1840afdba1fbab747c049d7.tar.gz cpython-ecaab837b6ef36edf1840afdba1fbab747c049d7.zip |
Committing the patch in issue 2965, so that weakref dicts have a closer
interface to normal dictionaries. keys(), values() and items() still return
iterators instead of views, but that can be fixed later (or not).
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r-- | Lib/weakref.py | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index 64d962c351f..5f672c66a7a 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -106,13 +106,13 @@ class WeakValueDictionary(collections.MutableMapping): L.append((key, o)) return L - def iteritems(self): + def items(self): for wr in self.data.values(): value = wr() if value is not None: yield wr.key, value - def iterkeys(self): + def keys(self): return iter(self.data.keys()) def __iter__(self): @@ -130,7 +130,7 @@ class WeakValueDictionary(collections.MutableMapping): """ return self.data.values() - def itervalues(self): + def values(self): for wr in self.data.values(): obj = wr() if obj is not None: @@ -186,14 +186,6 @@ class WeakValueDictionary(collections.MutableMapping): """ return self.data.values() - def values(self): - L = [] - for wr in self.data.values(): - o = wr() - if o is not None: - L.append(o) - return L - class KeyedRef(ref): """Specialized reference that includes a key corresponding to the value. @@ -270,20 +262,12 @@ class WeakKeyDictionary(collections.MutableMapping): return wr in self.data def items(self): - L = [] - for key, value in self.data.items(): - o = key() - if o is not None: - L.append((o, value)) - return L - - def iteritems(self): for wr, value in self.data.items(): key = wr() if key is not None: yield key, value - def iterkeyrefs(self): + def keyrefs(self): """Return an iterator that yields the weak references to the keys. The references are not guaranteed to be 'live' at the time @@ -295,7 +279,7 @@ class WeakKeyDictionary(collections.MutableMapping): """ return self.data.keys() - def iterkeys(self): + def keys(self): for wr in self.data.keys(): obj = wr() if obj is not None: @@ -304,7 +288,7 @@ class WeakKeyDictionary(collections.MutableMapping): def __iter__(self): return iter(self.keys()) - def itervalues(self): + def values(self): return iter(self.data.values()) def keyrefs(self): @@ -319,14 +303,6 @@ class WeakKeyDictionary(collections.MutableMapping): """ return self.data.keys() - def keys(self): - L = [] - for wr in self.data.keys(): - o = wr() - if o is not None: - L.append(o) - return L - def popitem(self): while 1: key, value = self.data.popitem() |