diff options
author | Guido van Rossum <guido@python.org> | 2007-02-11 06:12:03 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-02-11 06:12:03 (GMT) |
commit | cc2b0161257495f859200bce0aea3ed7e646feb3 (patch) | |
tree | ba09aba0de6447bef5be59b43fb86d17d760833d /Lib/UserDict.py | |
parent | 4e66dfcdc495218ad5f98b12ad6b4b2b05630ab0 (diff) | |
download | cpython-cc2b0161257495f859200bce0aea3ed7e646feb3.zip cpython-cc2b0161257495f859200bce0aea3ed7e646feb3.tar.gz cpython-cc2b0161257495f859200bce0aea3ed7e646feb3.tar.bz2 |
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
and .keys(), .items(), .values() return dict views.
The dict views aren't fully functional yet; in particular, they can't
be compared to sets yet. but they are useful as "iterator wells".
There are still 27 failing unit tests; I expect that many of these
have fairly trivial fixes, but there are so many, I could use help.
Diffstat (limited to 'Lib/UserDict.py')
-rw-r--r-- | Lib/UserDict.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py index 1190221..fa1deec 100644 --- a/Lib/UserDict.py +++ b/Lib/UserDict.py @@ -42,9 +42,9 @@ class UserDict: return c def keys(self): return self.data.keys() def items(self): return self.data.items() - def iteritems(self): return self.data.iteritems() - def iterkeys(self): return self.data.iterkeys() - def itervalues(self): return self.data.itervalues() + def iteritems(self): return self.data.items() + def iterkeys(self): return self.data.keys() + def itervalues(self): return self.data.values() def values(self): return self.data.values() def update(self, dict=None, **kwargs): if dict is None: @@ -111,12 +111,12 @@ class DictMixin: # fourth level uses definitions from lower levels def itervalues(self): - for _, v in self.iteritems(): + for _, v in self.items(): yield v def values(self): - return [v for _, v in self.iteritems()] + return [v for _, v in self.items()] def items(self): - return list(self.iteritems()) + return list(self.items()) def clear(self): for key in self.keys(): del self[key] @@ -140,7 +140,7 @@ class DictMixin: return value def popitem(self): try: - k, v = self.iteritems().next() + k, v = self.items().next() except StopIteration: raise KeyError, 'container is empty' del self[k] @@ -152,6 +152,9 @@ class DictMixin: elif hasattr(other, 'iteritems'): # iteritems saves memory and lookups for k, v in other.iteritems(): self[k] = v + elif hasattr(other, 'items'): # items may also save memory and lookups + for k, v in other.items(): + self[k] = v elif hasattr(other, 'keys'): for k in other.keys(): self[k] = other[k] @@ -166,14 +169,14 @@ class DictMixin: except KeyError: return default def __repr__(self): - return repr(dict(self.iteritems())) + return repr(dict(self.items())) def __eq__(self, other): if isinstance(other, DictMixin): - other = dict(other.iteritems()) - return dict(self.iteritems()) == other + other = dict(other.items()) + return dict(self.items()) == other def __ne__(self, other): if isinstance(other, DictMixin): - other = dict(other.iteritems()) - return dict(self.iteritems()) != other + other = dict(other.items()) + return dict(self.items()) != other def __len__(self): return len(self.keys()) |