changeset: 40809:f340cb045bf9 parent: 40807:f229645d607d user: Guido van Rossum date: Sun Feb 11 06:12:03 2007 +0000 files: Include/abstract.h Lib/ConfigParser.py Lib/Cookie.py Lib/UserDict.py Lib/_LWPCookieJar.py Lib/_strptime.py Lib/_threading_local.py Lib/base64.py Lib/compiler/ast.py Lib/compiler/misc.py Lib/compiler/pyassem.py Lib/cookielib.py Lib/copy.py Lib/csv.py Lib/ctypes/test/__init__.py Lib/difflib.py Lib/distutils/sysconfig.py Lib/dumbdbm.py Lib/encodings/punycode.py Lib/filecmp.py Lib/htmlentitydefs.py Lib/httplib.py Lib/mailbox.py Lib/mailcap.py Lib/mhlib.py Lib/pickle.py Lib/profile.py Lib/pstats.py Lib/pyclbr.py Lib/rfc822.py Lib/shelve.py Lib/symbol.py Lib/symtable.py Lib/test/fork_wait.py Lib/test/mapping_tests.py Lib/test/pickletester.py Lib/test/string_tests.py Lib/test/test_anydbm.py Lib/test/test_array.py Lib/test/test_bsddb.py Lib/test/test_builtin.py Lib/test/test_cfgparser.py Lib/test/test_cgi.py Lib/test/test_compile.py Lib/test/test_cookie.py Lib/test/test_copy.py Lib/test/test_descr.py Lib/test/test_dictviews.py Lib/test/test_iter.py Lib/test/test_iterlen.py Lib/test/test_itertools.py Lib/test/test_mailbox.py Lib/test/test_mhlib.py Lib/test/test_richcmp.py Lib/test/test_site.py Lib/test/test_support.py Lib/test/test_urllib2.py Lib/test/test_userdict.py Lib/test/test_uuid.py Lib/test/test_weakref.py Lib/test/test_xmlrpc.py Lib/threading.py Lib/token.py Lib/trace.py Lib/urllib2.py Lib/weakref.py Lib/xml/etree/ElementTree.py Misc/NEWS Modules/cPickle.c Modules/collectionsmodule.c Objects/abstract.c Objects/dictobject.c Objects/typeobject.c description: - 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. diff -r f229645d607d -r f340cb045bf9 Include/abstract.h --- a/Include/abstract.h Sat Feb 10 22:53:17 2007 +0000 +++ b/Include/abstract.h Sun Feb 11 06:12:03 2007 +0000 @@ -1127,37 +1127,28 @@ */ - /* Implemented as macro: - - PyObject *PyMapping_Keys(PyObject *o); + PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o); - On success, return a list of the keys in object o. On - failure, return NULL. This is equivalent to the Python - expression: o.keys(). + /* + On success, return a list or tuple of the keys in object o. + On failure, return NULL. */ -#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL) - /* Implemented as macro: - - PyObject *PyMapping_Values(PyObject *o); + PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o); - On success, return a list of the values in object o. On - failure, return NULL. This is equivalent to the Python - expression: o.values(). + /* + On success, return a list or tuple of the values in object o. + On failure, return NULL. */ -#define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL) - /* Implemented as macro: - - PyObject *PyMapping_Items(PyObject *o); + PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o); - On success, return a list of the items in object o, where - each item is a tuple containing a key-value pair. On - failure, return NULL. This is equivalent to the Python - expression: o.items(). + /* + On success, return a list or tuple of the items in object o, + where each item is a tuple containing a key-value pair. + On failure, return NULL. */ -#define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL) PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key); diff -r f229645d607d -r f340cb045bf9 Lib/ConfigParser.py --- a/Lib/ConfigParser.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/ConfigParser.py Sun Feb 11 06:12:03 2007 +0000 @@ -214,7 +214,7 @@ def sections(self): """Return a list of section names, excluding [DEFAULT]""" # self._sections will never have [DEFAULT] in it - return self._sections.keys() + return list(self._sections.keys()) def add_section(self, section): """Create a new section in the configuration. @@ -242,7 +242,7 @@ opts.update(self._defaults) if '__name__' in opts: del opts['__name__'] - return opts.keys() + return list(opts.keys()) def read(self, filenames): """Read and parse a filename or a list of filenames. @@ -547,7 +547,7 @@ if vars: for key, value in vars.items(): d[self.optionxform(key)] = value - options = d.keys() + options = list(d.keys()) if "__name__" in options: options.remove("__name__") if raw: diff -r f229645d607d -r f340cb045bf9 Lib/Cookie.py --- a/Lib/Cookie.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/Cookie.py Sun Feb 11 06:12:03 2007 +0000 @@ -488,8 +488,7 @@ # Now add any defined attributes if attrs is None: attrs = self._reserved - items = self.items() - items.sort() + items = sorted(self.items()) for K,V in items: if V == "": continue if K not in attrs: continue @@ -582,8 +581,7 @@ def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"): """Return a string suitable for HTTP.""" result = [] - items = self.items() - items.sort() + items = sorted(self.items()) for K,V in items: result.append( V.output(attrs, header) ) return sep.join(result) @@ -593,8 +591,7 @@ def __repr__(self): L = [] - items = self.items() - items.sort() + items = sorted(self.items()) for K,V in items: L.append( '%s=%s' % (K,repr(V.value) ) ) return '<%s: %s>' % (self.__class__.__name__, _spacejoin(L)) @@ -602,8 +599,7 @@ def js_output(self, attrs=None): """Return a string suitable for JavaScript.""" result = [] - items = self.items() - items.sort() + items = sorted(self.items()) for K,V in items: result.append( V.js_output(attrs) ) return _nulljoin(result) diff -r f229645d607d -r f340cb045bf9 Lib/UserDict.py --- a/Lib/UserDict.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/UserDict.py Sun Feb 11 06:12:03 2007 +0000 @@ -42,9 +42,9 @@ 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 @@ # 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 @@ 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 @@ 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 @@ 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()) diff -r f229645d607d -r f340cb045bf9 Lib/_LWPCookieJar.py --- a/Lib/_LWPCookieJar.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/_LWPCookieJar.py Sun Feb 11 06:12:03 2007 +0000 @@ -37,8 +37,7 @@ if cookie.comment: h.append(("comment", cookie.comment)) if cookie.comment_url: h.append(("commenturl", cookie.comment_url)) - keys = cookie._rest.keys() - keys.sort() + keys = sorted(cookie._rest.keys()) for k in keys: h.append((k, str(cookie._rest[k]))) diff -r f229645d607d -r f340cb045bf9 Lib/_strptime.py --- a/Lib/_strptime.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/_strptime.py Sun Feb 11 06:12:03 2007 +0000 @@ -338,7 +338,7 @@ # values weekday = julian = -1 found_dict = found.groupdict() - for group_key in found_dict.iterkeys(): + for group_key in found_dict.keys(): # Directives not explicitly handled below: # c, x, X # handled by making out of other directives diff -r f229645d607d -r f340cb045bf9 Lib/_threading_local.py --- a/Lib/_threading_local.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/_threading_local.py Sun Feb 11 06:12:03 2007 +0000 @@ -28,8 +28,7 @@ >>> log = [] >>> def f(): - ... items = mydata.__dict__.items() - ... items.sort() + ... items = sorted(mydata.__dict__.items()) ... log.append(items) ... mydata.number = 11 ... log.append(mydata.number) diff -r f229645d607d -r f340cb045bf9 Lib/base64.py --- a/Lib/base64.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/base64.py Sun Feb 11 06:12:03 2007 +0000 @@ -126,9 +126,7 @@ 8: 'I', 17: 'R', 26: '2', } -_b32tab = _b32alphabet.items() -_b32tab.sort() -_b32tab = [v for k, v in _b32tab] +_b32tab = [v for k, v in sorted(_b32alphabet.items())] _b32rev = dict([(v, int(k)) for k, v in _b32alphabet.items()]) diff -r f229645d607d -r f340cb045bf9 Lib/compiler/ast.py --- a/Lib/compiler/ast.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/compiler/ast.py Sun Feb 11 06:12:03 2007 +0000 @@ -1337,6 +1337,6 @@ def __repr__(self): return "Yield(%s)" % (repr(self.value),) -for name, obj in globals().items(): +for name, obj in list(globals().items()): if isinstance(obj, type) and issubclass(obj, Node): nodes[name.lower()] = obj diff -r f229645d607d -r f340cb045bf9 Lib/compiler/misc.py --- a/Lib/compiler/misc.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/compiler/misc.py Sun Feb 11 06:12:03 2007 +0000 @@ -18,7 +18,7 @@ def add(self, elt): self.elts[elt] = elt def elements(self): - return self.elts.keys() + return list(self.elts.keys()) def has_elt(self, elt): return elt in self.elts def remove(self, elt): diff -r f229645d607d -r f340cb045bf9 Lib/compiler/pyassem.py --- a/Lib/compiler/pyassem.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/compiler/pyassem.py Sun Feb 11 06:12:03 2007 +0000 @@ -504,7 +504,7 @@ if name in cells] for name in self.cellvars: del cells[name] - self.cellvars = self.cellvars + cells.keys() + self.cellvars = self.cellvars + list(cells.keys()) self.closure = self.cellvars + self.freevars def _lookupName(self, name, list): @@ -573,7 +573,7 @@ # similarly for other opcodes... - for name, obj in locals().items(): + for name, obj in list(locals().items()): if name[:9] == "_convert_": opname = name[9:] _converters[opname] = obj diff -r f229645d607d -r f340cb045bf9 Lib/cookielib.py --- a/Lib/cookielib.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/cookielib.py Sun Feb 11 06:12:03 2007 +0000 @@ -1171,8 +1171,7 @@ def vals_sorted_by_key(adict): - keys = adict.keys() - keys.sort() + keys = sorted(adict.keys()) return map(adict.get, keys) def deepvalues(mapping): diff -r f229645d607d -r f340cb045bf9 Lib/copy.py --- a/Lib/copy.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/copy.py Sun Feb 11 06:12:03 2007 +0000 @@ -230,7 +230,7 @@ def _deepcopy_dict(x, memo): y = {} memo[id(x)] = y - for key, value in x.iteritems(): + for key, value in x.items(): y[deepcopy(key, memo)] = deepcopy(value, memo) return y d[dict] = _deepcopy_dict @@ -302,7 +302,7 @@ if state is not None: y.__dict__.update(state) if slotstate is not None: - for key, value in slotstate.iteritems(): + for key, value in slotstate.items(): setattr(y, key, value) return y @@ -337,7 +337,7 @@ def __getstate__(self): return {'a': self.a, 'arg': self.arg} def __setstate__(self, state): - for key, value in state.iteritems(): + for key, value in state.items(): setattr(self, key, value) def __deepcopy__(self, memo=None): new = self.__class__(deepcopy(self.arg, memo)) diff -r f229645d607d -r f340cb045bf9 Lib/csv.py --- a/Lib/csv.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/csv.py Sun Feb 11 06:12:03 2007 +0000 @@ -278,7 +278,7 @@ charFrequency[char] = metaFrequency for char in charFrequency.keys(): - items = charFrequency[char].items() + items = list(charFrequency[char].items()) if len(items) == 1 and items[0][0] == 0: continue # get the mode of the frequencies @@ -308,7 +308,7 @@ consistency -= 0.01 if len(delims) == 1: - delim = delims.keys()[0] + delim = list(delims.keys())[0] skipinitialspace = (data[0].count(delim) == data[0].count("%c " % delim)) return (delim, skipinitialspace) @@ -367,7 +367,7 @@ if len(row) != columns: continue # skip rows that have irregular number of columns - for col in columnTypes.keys(): + for col in list(columnTypes.keys()): for thisType in [int, int, float, complex]: try: diff -r f229645d607d -r f340cb045bf9 Lib/ctypes/test/__init__.py --- a/Lib/ctypes/test/__init__.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/ctypes/test/__init__.py Sun Feb 11 06:12:03 2007 +0000 @@ -41,7 +41,7 @@ hasattr(package.__loader__, '_files')): path = package.__name__.replace(".", os.path.sep) mask = os.path.join(path, mask) - for fnm in package.__loader__._files.iterkeys(): + for fnm in package.__loader__._files.keys(): if fnmatch.fnmatchcase(fnm, mask): yield os.path.splitext(fnm)[0].replace(os.path.sep, ".") else: diff -r f229645d607d -r f340cb045bf9 Lib/difflib.py --- a/Lib/difflib.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/difflib.py Sun Feb 11 06:12:03 2007 +0000 @@ -331,7 +331,7 @@ junkdict = {} if isjunk: for d in populardict, b2j: - for elt in d.keys(): + for elt in list(d.keys()): if isjunk(elt): junkdict[elt] = 1 del d[elt] diff -r f229645d607d -r f340cb045bf9 Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/distutils/sysconfig.py Sun Feb 11 06:12:03 2007 +0000 @@ -271,7 +271,7 @@ # do variable interpolation here while notdone: - for name in notdone.keys(): + for name in list(notdone): value = notdone[name] m = _findvar1_rx.search(value) or _findvar2_rx.search(value) if m: diff -r f229645d607d -r f340cb045bf9 Lib/dumbdbm.py --- a/Lib/dumbdbm.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/dumbdbm.py Sun Feb 11 06:12:03 2007 +0000 @@ -109,7 +109,7 @@ f = self._open(self._dirfile, 'w') self._chmod(self._dirfile) - for key, pos_and_siz_pair in self._index.iteritems(): + for key, pos_and_siz_pair in self._index.items(): f.write("%r, %r\n" % (key, pos_and_siz_pair)) f.close() @@ -202,7 +202,7 @@ return key in self._index def iterkeys(self): - return self._index.iterkeys() + return self._index.keys() __iter__ = iterkeys def __len__(self): diff -r f229645d607d -r f340cb045bf9 Lib/encodings/punycode.py --- a/Lib/encodings/punycode.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/encodings/punycode.py Sun Feb 11 06:12:03 2007 +0000 @@ -17,8 +17,7 @@ base.append(c) else: extended[c] = 1 - extended = extended.keys() - extended.sort() + extended = sorted(extended.keys()) return "".join(base).encode("ascii"),extended def selective_len(str, max): diff -r f229645d607d -r f340cb045bf9 Lib/filecmp.py --- a/Lib/filecmp.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/filecmp.py Sun Feb 11 06:12:03 2007 +0000 @@ -187,7 +187,7 @@ def phase4_closure(self): # Recursively call phase4() on subdirectories self.phase4() - for sd in self.subdirs.itervalues(): + for sd in self.subdirs.values(): sd.phase4_closure() def report(self): # Print a report on the differences between a and b @@ -217,13 +217,13 @@ def report_partial_closure(self): # Print reports on self and on subdirs self.report() - for sd in self.subdirs.itervalues(): + for sd in self.subdirs.values(): print() sd.report() def report_full_closure(self): # Report on self and subdirs recursively self.report() - for sd in self.subdirs.itervalues(): + for sd in self.subdirs.values(): print() sd.report_full_closure() diff -r f229645d607d -r f340cb045bf9 Lib/htmlentitydefs.py --- a/Lib/htmlentitydefs.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/htmlentitydefs.py Sun Feb 11 06:12:03 2007 +0000 @@ -263,7 +263,7 @@ # (or a character reference if the character is outside the Latin-1 range) entitydefs = {} -for (name, codepoint) in name2codepoint.iteritems(): +for (name, codepoint) in name2codepoint.items(): codepoint2name[codepoint] = name if codepoint <= 0xff: entitydefs[name] = chr(codepoint) diff -r f229645d607d -r f340cb045bf9 Lib/httplib.py --- a/Lib/httplib.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/httplib.py Sun Feb 11 06:12:03 2007 +0000 @@ -611,7 +611,7 @@ """Return list of (header, value) tuples.""" if self.msg is None: raise ResponseNotReady() - return self.msg.items() + return list(self.msg.items()) class HTTPConnection: @@ -902,7 +902,7 @@ if thelen is not None: self.putheader('Content-Length',thelen) - for hdr, value in headers.iteritems(): + for hdr, value in headers.items(): self.putheader(hdr, value) self.endheaders() diff -r f229645d607d -r f340cb045bf9 Lib/mailbox.py --- a/Lib/mailbox.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/mailbox.py Sun Feb 11 06:12:03 2007 +0000 @@ -95,11 +95,11 @@ def keys(self): """Return a list of keys.""" - return list(self.iterkeys()) + return list(self.keys()) def itervalues(self): """Return an iterator over all messages.""" - for key in self.iterkeys(): + for key in self.keys(): try: value = self[key] except KeyError: @@ -107,15 +107,15 @@ yield value def __iter__(self): - return self.itervalues() + return self.values() def values(self): """Return a list of messages. Memory intensive.""" - return list(self.itervalues()) + return list(self.values()) def iteritems(self): """Return an iterator over (key, message) tuples.""" - for key in self.iterkeys(): + for key in self.keys(): try: value = self[key] except KeyError: @@ -124,7 +124,7 @@ def items(self): """Return a list of (key, message) tuples. Memory intensive.""" - return list(self.iteritems()) + return list(self.items()) def __contains__(self, key): """Return True if the keyed message exists, False otherwise.""" @@ -136,7 +136,7 @@ def clear(self): """Delete all messages.""" - for key in self.iterkeys(): + for key in self.keys(): self.discard(key) def pop(self, key, default=None): @@ -150,7 +150,7 @@ def popitem(self): """Delete an arbitrary (key, message) pair and return it.""" - for key in self.iterkeys(): + for key in self.keys(): return (key, self.pop(key)) # This is only run once. else: raise KeyError('No messages in mailbox') @@ -158,7 +158,7 @@ def update(self, arg=None): """Change the messages that correspond to certain keys.""" if hasattr(arg, 'iteritems'): - source = arg.iteritems() + source = arg.items() elif hasattr(arg, 'items'): source = arg.items() else: @@ -477,7 +477,7 @@ def next(self): """Return the next message in a one-time iteration.""" if not hasattr(self, '_onetime_keys'): - self._onetime_keys = self.iterkeys() + self._onetime_keys = self.keys() while True: try: return self[self._onetime_keys.next()] @@ -950,7 +950,7 @@ def __len__(self): """Return a count of messages in the mailbox.""" - return len(list(self.iterkeys())) + return len(list(self.keys())) def lock(self): """Lock the mailbox.""" @@ -1038,7 +1038,7 @@ f = open(os.path.join(self._path, '.mh_sequences'), 'r+') try: os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC)) - for name, keys in sequences.iteritems(): + for name, keys in sequences.items(): if len(keys) == 0: continue f.write('%s:' % name) @@ -1067,7 +1067,7 @@ sequences = self.get_sequences() prev = 0 changes = [] - for key in self.iterkeys(): + for key in self.keys(): if key - 1 != prev: changes.append((key, prev + 1)) if hasattr(os, 'link'): @@ -1091,7 +1091,7 @@ """Inspect a new MHMessage and update sequences appropriately.""" pending_sequences = message.get_sequences() all_sequences = self.get_sequences() - for name, key_list in all_sequences.iteritems(): + for name, key_list in all_sequences.items(): if name in pending_sequences: key_list.append(key) elif key in key_list: diff -r f229645d607d -r f340cb045bf9 Lib/mailcap.py --- a/Lib/mailcap.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/mailcap.py Sun Feb 11 06:12:03 2007 +0000 @@ -24,7 +24,7 @@ continue morecaps = readmailcapfile(fp) fp.close() - for key, value in morecaps.iteritems(): + for key, value in morecaps.items(): if not key in caps: caps[key] = value else: diff -r f229645d607d -r f340cb045bf9 Lib/mhlib.py --- a/Lib/mhlib.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/mhlib.py Sun Feb 11 06:12:03 2007 +0000 @@ -314,7 +314,7 @@ """Write the set of sequences back to the folder.""" fullname = self.getsequencesfilename() f = None - for key, seq in sequences.iteritems(): + for key, seq in sequences.items(): s = IntSet('', ' ') s.fromlist(seq) if not f: f = open(fullname, 'w') diff -r f229645d607d -r f340cb045bf9 Lib/pickle.py --- a/Lib/pickle.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/pickle.py Sun Feb 11 06:12:03 2007 +0000 @@ -666,7 +666,7 @@ write(MARK + DICT) self.memoize(obj) - self._batch_setitems(obj.iteritems()) + self._batch_setitems(iter(obj.items())) dispatch[DictionaryType] = save_dict if not PyStringMap is None: diff -r f229645d607d -r f340cb045bf9 Lib/profile.py --- a/Lib/profile.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/profile.py Sun Feb 11 06:12:03 2007 +0000 @@ -439,10 +439,10 @@ def snapshot_stats(self): self.stats = {} - for func, (cc, ns, tt, ct, callers) in self.timings.iteritems(): + for func, (cc, ns, tt, ct, callers) in self.timings.items(): callers = callers.copy() nc = 0 - for callcnt in callers.itervalues(): + for callcnt in callers.values(): nc += callcnt self.stats[func] = cc, nc, tt, ct, callers diff -r f229645d607d -r f340cb045bf9 Lib/pstats.py --- a/Lib/pstats.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/pstats.py Sun Feb 11 06:12:03 2007 +0000 @@ -163,7 +163,7 @@ self.fcn_list = None - for func, stat in other.stats.iteritems(): + for func, stat in other.stats.items(): if func in self.stats: old_func_stat = self.stats[func] else: @@ -199,7 +199,7 @@ if not self.sort_arg_dict: self.sort_arg_dict = dict = {} bad_list = {} - for word, tup in self.sort_arg_dict_default.iteritems(): + for word, tup in self.sort_arg_dict_default.items(): fragment = word while fragment: if not fragment: @@ -234,7 +234,7 @@ connector = ", " stats_list = [] - for func, (cc, nc, tt, ct, callers) in self.stats.iteritems(): + for func, (cc, nc, tt, ct, callers) in self.stats.items(): stats_list.append((cc, nc, tt, ct) + func + (func_std_string(func), func)) @@ -254,12 +254,12 @@ oldstats = self.stats self.stats = newstats = {} max_name_len = 0 - for func, (cc, nc, tt, ct, callers) in oldstats.iteritems(): + for func, (cc, nc, tt, ct, callers) in oldstats.items(): newfunc = func_strip_path(func) if len(func_std_string(newfunc)) > max_name_len: max_name_len = len(func_std_string(newfunc)) newcallers = {} - for func2, caller in callers.iteritems(): + for func2, caller in callers.items(): newcallers[func_strip_path(func2)] = caller if newfunc in newstats: @@ -282,10 +282,10 @@ def calc_callees(self): if self.all_callees: return self.all_callees = all_callees = {} - for func, (cc, nc, tt, ct, callers) in self.stats.iteritems(): + for func, (cc, nc, tt, ct, callers) in self.stats.items(): if not func in all_callees: all_callees[func] = {} - for func2, caller in callers.iteritems(): + for func2, caller in callers.items(): if not func2 in all_callees: all_callees[func2] = {} all_callees[func2][func] = caller @@ -394,9 +394,9 @@ print("Function ".ljust(name_size) + column_title, file=self.stream) # print sub-header only if we have new-style callers subheader = False - for cc, nc, tt, ct, callers in self.stats.itervalues(): + for cc, nc, tt, ct, callers in self.stats.values(): if callers: - value = callers.itervalues().next() + value = iter(callers.values()).next() subheader = isinstance(value, tuple) break if subheader: @@ -407,8 +407,7 @@ if not call_dict: print(file=self.stream) return - clist = call_dict.keys() - clist.sort() + clist = sorted(call_dict.keys()) indent = "" for func in clist: name = func_std_string(func) @@ -508,9 +507,9 @@ def add_callers(target, source): """Combine two caller lists in a single list.""" new_callers = {} - for func, caller in target.iteritems(): + for func, caller in target.items(): new_callers[func] = caller - for func, caller in source.iteritems(): + for func, caller in source.items(): if func in new_callers: new_callers[func] = caller + new_callers[func] else: @@ -520,7 +519,7 @@ def count_calls(callers): """Sum the caller statistics to get total number of calls received.""" nc = 0 - for calls in callers.itervalues(): + for calls in callers.values(): nc += calls return nc @@ -642,7 +641,7 @@ self.stats.sort_stats(*line.split()) else: print("Valid sort keys (unique prefixes are accepted):", file=self.stream) - for (key, value) in Stats.sort_arg_dict_default.iteritems(): + for (key, value) in Stats.sort_arg_dict_default.items(): print("%s -- %s" % (key, value[1]), file=self.stream) return 0 def help_sort(self): diff -r f229645d607d -r f340cb045bf9 Lib/pyclbr.py --- a/Lib/pyclbr.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/pyclbr.py Sun Feb 11 06:12:03 2007 +0000 @@ -329,7 +329,7 @@ for obj in objs: if isinstance(obj, Class): print("class", obj.name, obj.super, obj.lineno) - methods = sorted(obj.methods.iteritems(), key=itemgetter(1)) + methods = sorted(obj.methods.items(), key=itemgetter(1)) for name, lineno in methods: if name != "__path__": print(" def", name, lineno) diff -r f229645d607d -r f340cb045bf9 Lib/rfc822.py --- a/Lib/rfc822.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/rfc822.py Sun Feb 11 06:12:03 2007 +0000 @@ -437,18 +437,18 @@ def keys(self): """Get all of a message's header field names.""" - return self.dict.keys() + return list(self.dict.keys()) def values(self): """Get all of a message's header field values.""" - return self.dict.values() + return list(self.dict.values()) def items(self): """Get all of a message's headers. Returns a list of name, value tuples. """ - return self.dict.items() + return list(self.dict.items()) def __str__(self): return ''.join(self.headers) diff -r f229645d607d -r f340cb045bf9 Lib/shelve.py --- a/Lib/shelve.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/shelve.py Sun Feb 11 06:12:03 2007 +0000 @@ -144,7 +144,7 @@ def sync(self): if self.writeback and self.cache: self.writeback = False - for key, entry in self.cache.iteritems(): + for key, entry in self.cache.items(): self[key] = entry self.writeback = True self.cache = {} diff -r f229645d607d -r f340cb045bf9 Lib/symbol.py --- a/Lib/symbol.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/symbol.py Sun Feb 11 06:12:03 2007 +0000 @@ -100,7 +100,7 @@ #--end constants-- sym_name = {} -for _name, _value in globals().items(): +for _name, _value in list(globals().items()): if type(_value) is type(0): sym_name[_value] = _name diff -r f229645d607d -r f340cb045bf9 Lib/symtable.py --- a/Lib/symtable.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/symtable.py Sun Feb 11 06:12:03 2007 +0000 @@ -13,7 +13,7 @@ def symtable(code, filename, compile_type): raw = _symtable.symtable(code, filename, compile_type) - for top in raw.itervalues(): + for top in raw.values(): if top.name == 'top': break return newSymbolTable(top, filename) diff -r f229645d607d -r f340cb045bf9 Lib/test/fork_wait.py --- a/Lib/test/fork_wait.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/fork_wait.py Sun Feb 11 06:12:03 2007 +0000 @@ -51,8 +51,7 @@ time.sleep(LONGSLEEP) - a = self.alive.keys() - a.sort() + a = sorted(self.alive.keys()) self.assertEquals(a, range(NUM_THREADS)) prefork_lives = self.alive.copy() diff -r f229645d607d -r f340cb045bf9 Lib/test/mapping_tests.py --- a/Lib/test/mapping_tests.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/mapping_tests.py Sun Feb 11 06:12:03 2007 +0000 @@ -73,13 +73,13 @@ self.assert_(hasattr(iter, '__iter__')) x = list(iter) self.assert_(set(x)==set(lst)==set(ref)) - check_iterandlist(d.iterkeys(), d.keys(), self.reference.keys()) + check_iterandlist(d.keys(), d.keys(), self.reference.keys()) check_iterandlist(iter(d), d.keys(), self.reference.keys()) - check_iterandlist(d.itervalues(), d.values(), self.reference.values()) - check_iterandlist(d.iteritems(), d.items(), self.reference.items()) + check_iterandlist(d.values(), d.values(), self.reference.values()) + check_iterandlist(d.items(), d.items(), self.reference.items()) #get - key, value = d.iteritems().next() - knownkey, knownvalue = self.other.iteritems().next() + key, value = d.items().next() + knownkey, knownvalue = self.other.items().next() self.assertEqual(d.get(key, knownvalue), value) self.assertEqual(d.get(knownkey, knownvalue), knownvalue) self.failIf(knownkey in d) @@ -104,8 +104,8 @@ self.assertEqual(dict(p), self.reference) d = self._full_mapping(self.reference) #setdefault - key, value = d.iteritems().next() - knownkey, knownvalue = self.other.iteritems().next() + key, value = d.items().next() + knownkey, knownvalue = self.other.items().next() self.assertEqual(d.setdefault(key, knownvalue), value) self.assertEqual(d[key], value) self.assertEqual(d.setdefault(knownkey, knownvalue), knownvalue) @@ -183,7 +183,7 @@ # Iterator d = self._empty_mapping() - d.update(self.other.iteritems()) + d.update(self.other.items()) self.assertEqual(d.items(), self.other.items()) # FIXME: Doesn't work with UserDict @@ -400,7 +400,7 @@ # iterator d = self._full_mapping({1:3, 2:4}) - d.update(self._full_mapping({1:2, 3:4, 5:6}).iteritems()) + d.update(self._full_mapping({1:2, 3:4, 5:6}).items()) self.assertEqual(d, {1:2, 2:4, 3:4, 5:6}) class SimpleUserDict: diff -r f229645d607d -r f340cb045bf9 Lib/test/pickletester.py --- a/Lib/test/pickletester.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/pickletester.py Sun Feb 11 06:12:03 2007 +0000 @@ -438,7 +438,7 @@ for proto in protocols: s = self.dumps(d, proto) x = self.loads(s) - self.assertEqual(x.keys(), [1]) + self.assertEqual(list(x.keys()), [1]) self.assert_(x[1] is x) def test_recursive_inst(self): @@ -461,7 +461,7 @@ x = self.loads(s) self.assertEqual(len(x), 1) self.assertEqual(dir(x[0]), dir(i)) - self.assertEqual(x[0].attr.keys(), [1]) + self.assertEqual(list(x[0].attr.keys()), [1]) self.assert_(x[0].attr[1] is x) def test_garyp(self): diff -r f229645d607d -r f340cb045bf9 Lib/test/string_tests.py --- a/Lib/test/string_tests.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/string_tests.py Sun Feb 11 06:12:03 2007 +0000 @@ -40,7 +40,7 @@ elif isinstance(obj, dict): return dict([ (self.fixtype(key), self.fixtype(value)) - for (key, value) in obj.iteritems() + for (key, value) in obj.items() ]) else: return obj diff -r f229645d607d -r f340cb045bf9 Lib/test/test_anydbm.py --- a/Lib/test/test_anydbm.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_anydbm.py Sun Feb 11 06:12:03 2007 +0000 @@ -72,10 +72,8 @@ f.close() def keys_helper(self, f): - keys = f.keys() - keys.sort() - dkeys = self._dict.keys() - dkeys.sort() + keys = sorted(f.keys()) + dkeys = sorted(self._dict.keys()) self.assertEqual(keys, dkeys) return keys diff -r f229645d607d -r f340cb045bf9 Lib/test/test_array.py --- a/Lib/test/test_array.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_array.py Sun Feb 11 06:12:03 2007 +0000 @@ -729,7 +729,7 @@ self.assertEqual(s.color, "blue") s.color = "red" self.assertEqual(s.color, "red") - self.assertEqual(s.__dict__.keys(), ["color"]) + self.assertEqual(list(s.__dict__.keys()), ["color"]) def test_nounicode(self): a = array.array(self.typecode, self.example) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_bsddb.py --- a/Lib/test/test_bsddb.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_bsddb.py Sun Feb 11 06:12:03 2007 +0000 @@ -15,7 +15,7 @@ def setUp(self): self.f = self.openmethod[0](self.fname, self.openflag, cachesize=32768) self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='') - for k, v in self.d.iteritems(): + for k, v in self.d.items(): self.f[k] = v def tearDown(self): @@ -29,7 +29,7 @@ pass def test_getitem(self): - for k, v in self.d.iteritems(): + for k, v in self.d.items(): self.assertEqual(self.f[k], v) def test_len(self): @@ -48,7 +48,7 @@ return self.f.close() self.f = self.openmethod[0](self.fname, 'w') - for k, v in self.d.iteritems(): + for k, v in self.d.items(): self.assertEqual(self.f[k], v) def assertSetEquals(self, seqn1, seqn2): @@ -61,9 +61,9 @@ self.assertSetEquals(d.keys(), f.keys()) self.assertSetEquals(d.values(), f.values()) self.assertSetEquals(d.items(), f.items()) - self.assertSetEquals(d.iterkeys(), f.iterkeys()) - self.assertSetEquals(d.itervalues(), f.itervalues()) - self.assertSetEquals(d.iteritems(), f.iteritems()) + self.assertSetEquals(d.keys(), f.keys()) + self.assertSetEquals(d.values(), f.values()) + self.assertSetEquals(d.items(), f.items()) def test_iter_while_modifying_values(self): if not hasattr(self.f, '__iter__'): @@ -94,7 +94,7 @@ if not hasattr(self.f, 'iteritems'): return - di = self.d.iteritems() + di = self.d.items() while 1: try: k, v = di.next() @@ -105,7 +105,7 @@ # it should behave the same as a dict. modifying values # of existing keys should not break iteration. (adding # or removing keys should) - fi = self.f.iteritems() + fi = self.f.items() while 1: try: k, v = fi.next() @@ -159,7 +159,7 @@ # test the iterator interface (if present) if hasattr(self.f, 'iteritems'): if debug: print("D") - i = self.f.iteritems() + i = self.f.items() k,v = i.next() if debug: print("E") self.f[k] = "please don't deadlock" @@ -198,7 +198,7 @@ # do the bsddb._DBWithCursor _iter_mixin internals leak cursors? nc1 = len(self.f._cursor_refs) # create iterator - i = self.f.iteritems() + i = self.f.items() nc2 = len(self.f._cursor_refs) # use the iterator (should run to the first yeild, creating the cursor) k, v = i.next() @@ -240,7 +240,7 @@ new = dict(y='life', u='of', i='brian') self.f.update(new) self.d.update(new) - for k, v in self.d.iteritems(): + for k, v in self.d.items(): self.assertEqual(self.f[k], v) def test_keyordering(self): diff -r f229645d607d -r f340cb045bf9 Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_builtin.py Sun Feb 11 06:12:03 2007 +0000 @@ -290,8 +290,8 @@ if key == 'a': return 12 raise KeyError - def keys(self): - return list('xyz') + def __iter__(self): + return iter('xyz') m = M() g = globals() @@ -313,8 +313,8 @@ if key == 'a': return 12 return dict.__getitem__(self, key) - def keys(self): - return list('xyz') + def __iter__(self): + return iter('xyz') d = D() self.assertEqual(eval('a', g, d), 12) @@ -346,8 +346,8 @@ class C: def __getitem__(self, item): raise KeyError(item) - def keys(self): - return 'a' + def __iter__(self): + return 'a' # XXX Not quite faithful to the SF bug... self.assertRaises(TypeError, eval, 'dir()', globals(), C()) # Done outside of the method test_z to get the correct scope @@ -522,8 +522,8 @@ unicode("123"): unicode("112233") } - for (cls, inps) in inputs.iteritems(): - for (inp, exp) in inps.iteritems(): + for (cls, inps) in inputs.items(): + for (inp, exp) in inps.items(): # make sure the output goes through __getitem__ # even if func is None self.assertEqual( diff -r f229645d607d -r f340cb045bf9 Lib/test/test_cfgparser.py --- a/Lib/test/test_cfgparser.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_cfgparser.py Sun Feb 11 06:12:03 2007 +0000 @@ -7,18 +7,13 @@ class SortedDict(UserDict.UserDict): def items(self): - result = self.data.items() - result.sort() - return result + return sorted(self.data.items()) def keys(self): - result = self.data.keys() - result.sort() - return result + return sorted(self.data.keys()) def values(self): - result = self.items() - return [i[1] for i in values] + return [i[1] for i in self.items()] def iteritems(self): return iter(self.items()) def iterkeys(self): return iter(self.keys()) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_cgi.py --- a/Lib/test/test_cgi.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_cgi.py Sun Feb 11 06:12:03 2007 +0000 @@ -118,9 +118,7 @@ ] def norm(seq): - if isinstance(seq, list): - seq.sort(key=repr) - return seq + return sorted(seq, key=repr) def first_elts(list): return map(lambda x:x[0], list) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_compile.py --- a/Lib/test/test_compile.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_compile.py Sun Feb 11 06:12:03 2007 +0000 @@ -53,8 +53,8 @@ raise KeyError def __setitem__(self, key, value): self.results = (key, value) - def keys(self): - return list('xyz') + def __iter__(self): + return iter('xyz') m = M() g = globals() diff -r f229645d607d -r f340cb045bf9 Lib/test/test_cookie.py --- a/Lib/test/test_cookie.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_cookie.py Sun Feb 11 06:12:03 2007 +0000 @@ -38,7 +38,7 @@ C.load(case['data']) self.assertEqual(repr(C), case['repr']) self.assertEqual(C.output(sep='\n'), case['output']) - for k, v in sorted(case['dict'].iteritems()): + for k, v in sorted(case['dict'].items()): self.assertEqual(C[k].value, v) def test_load(self): diff -r f229645d607d -r f340cb045bf9 Lib/test/test_copy.py --- a/Lib/test/test_copy.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_copy.py Sun Feb 11 06:12:03 2007 +0000 @@ -491,7 +491,7 @@ def test_reduce_5tuple(self): class C(dict): def __reduce__(self): - return (C, (), self.__dict__, None, self.iteritems()) + return (C, (), self.__dict__, None, self.items()) def __eq__(self, other): return (dict(self) == dict(other) and self.__dict__ == other.__dict__) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_descr.py --- a/Lib/test/test_descr.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_descr.py Sun Feb 11 06:12:03 2007 +0000 @@ -183,7 +183,7 @@ d = dict({1: 2, 'a': 'b'}) vereq(d, {1: 2, 'a': 'b'}) vereq(d, dict(d.items())) - vereq(d, dict(d.iteritems())) + vereq(d, dict(d.items())) d = dict({'one':1, 'two':2}) vereq(d, dict(one=1, two=2)) vereq(d, dict(**d)) @@ -541,10 +541,10 @@ class C(spam.spamdict): def foo(self): return 1 a = C() - vereq(a.items(), []) + vereq(list(a.items()), []) vereq(a.foo(), 1) a['foo'] = 'bar' - vereq(a.items(), [('foo', 'bar')]) + vereq(list(a.items()), [('foo', 'bar')]) vereq(a.getstate(), 0) a.setstate(100) vereq(a.getstate(), 100) @@ -714,7 +714,7 @@ # named _get_x and/or _set_x are found def __new__(metaclass, name, bases, dict): hits = {} - for key, val in dict.iteritems(): + for key, val in dict.items(): if key.startswith("_get_"): key = key[5:] get, set = hits.get(key, (None, None)) @@ -725,7 +725,7 @@ get, set = hits.get(key, (None, None)) set = val hits[key] = get, set - for key, (get, set) in hits.iteritems(): + for key, (get, set) in hits.items(): dict[key] = property(get, set) return super(autoproperty, metaclass).__new__(metaclass, name, bases, dict) @@ -820,9 +820,9 @@ type({}).__init__(self) C.__init__(self) d = D() - vereq(d.keys(), []) + vereq(list(d.keys()), []) d["hello"] = "world" - vereq(d.items(), [("hello", "world")]) + vereq(list(d.items()), [("hello", "world")]) vereq(d["hello"], "world") vereq(d.getstate(), 0) d.setstate(10) @@ -2676,9 +2676,7 @@ cPickle = None def sorteditems(d): - L = d.items() - L.sort() - return L + return sorted(d.items()) global C class C(object): @@ -3193,7 +3191,7 @@ def meth(self): pass if verbose: print("Testing dict-proxy iterkeys...") - keys = [ key for key in C.__dict__.iterkeys() ] + keys = [ key for key in C.__dict__.keys() ] keys.sort() vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth']) @@ -3202,7 +3200,7 @@ def meth(self): pass if verbose: print("Testing dict-proxy itervalues...") - values = [ values for values in C.__dict__.itervalues() ] + values = [ values for values in C.__dict__.values() ] vereq(len(values), 5) def dictproxyiteritems(): @@ -3210,7 +3208,7 @@ def meth(self): pass if verbose: print("Testing dict-proxy iteritems...") - keys = [ key for (key, value) in C.__dict__.iteritems() ] + keys = [ key for (key, value) in C.__dict__.items() ] keys.sort() vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth']) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_dictviews.py --- a/Lib/test/test_dictviews.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_dictviews.py Sun Feb 11 06:12:03 2007 +0000 @@ -4,19 +4,19 @@ class DictSetTest(unittest.TestCase): def test_constructors_not_callable(self): - kt = type({}.KEYS()) + kt = type({}.keys()) self.assertRaises(TypeError, kt, {}) self.assertRaises(TypeError, kt) - it = type({}.ITEMS()) + it = type({}.items()) self.assertRaises(TypeError, it, {}) self.assertRaises(TypeError, it) - vt = type({}.VALUES()) + vt = type({}.values()) self.assertRaises(TypeError, vt, {}) self.assertRaises(TypeError, vt) def test_dict_keys(self): d = {1: 10, "a": "ABC"} - keys = d.KEYS() + keys = d.keys() self.assertEqual(set(keys), {1, "a"}) self.assertEqual(len(keys), 2) self.assert_(1 in keys) @@ -26,7 +26,7 @@ def test_dict_items(self): d = {1: 10, "a": "ABC"} - items = d.ITEMS() + items = d.items() self.assertEqual(set(items), {(1, 10), ("a", "ABC")}) self.assertEqual(len(items), 2) self.assert_((1, 10) in items) @@ -39,7 +39,7 @@ def test_dict_values(self): d = {1: 10, "a": "ABC"} - values = d.VALUES() + values = d.values() self.assertEqual(set(values), {10, "ABC"}) self.assertEqual(len(values), 2) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_iter.py --- a/Lib/test/test_iter.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_iter.py Sun Feb 11 06:12:03 2007 +0000 @@ -365,8 +365,8 @@ d = {"one": 1, "two": 2, "three": 3} self.assertEqual(max(d), "two") self.assertEqual(min(d), "one") - self.assertEqual(max(d.itervalues()), 3) - self.assertEqual(min(iter(d.itervalues())), 1) + self.assertEqual(max(d.values()), 3) + self.assertEqual(min(iter(d.values())), 1) f = open(TESTFN, "w") try: @@ -402,7 +402,7 @@ for i in range(5)] self.assertEqual(map(None, d, SequenceClass(5), - iter(d.iterkeys())), + iter(d.keys())), expected) f = open(TESTFN, "w") @@ -437,7 +437,7 @@ [(0,), (1,), (2,)]) d = {"one": 1, "two": 2, "three": 3} - self.assertEqual(d.items(), list(zip(d, d.itervalues()))) + self.assertEqual(d.items(), list(zip(d, d.values()))) # Generate all ints starting at constructor arg. class IntsFrom: @@ -559,13 +559,13 @@ d = {"one": 1, "two": 2, "three": 3, 1j: 2j} for k in d: self.assert_(k in d) - self.assert_(k not in d.itervalues()) + self.assert_(k not in d.values()) for v in d.values(): - self.assert_(v in d.itervalues()) + self.assert_(v in d.values()) self.assert_(v not in d) - for k, v in d.iteritems(): - self.assert_((k, v) in d.iteritems()) - self.assert_((v, k) not in d.iteritems()) + for k, v in d.items(): + self.assert_((k, v) in d.items()) + self.assert_((v, k) not in d.items()) f = open(TESTFN, "w") try: @@ -600,9 +600,9 @@ d = {"one": 3, "two": 3, "three": 3, 1j: 2j} for k in d: self.assertEqual(countOf(d, k), 1) - self.assertEqual(countOf(d.itervalues(), 3), 3) - self.assertEqual(countOf(d.itervalues(), 2j), 1) - self.assertEqual(countOf(d.itervalues(), 1j), 0) + self.assertEqual(countOf(d.values(), 3), 3) + self.assertEqual(countOf(d.values(), 2j), 1) + self.assertEqual(countOf(d.values(), 1j), 0) f = open(TESTFN, "w") try: @@ -744,7 +744,7 @@ else: self.fail("should have raised TypeError") - a, b, c = {1: 42, 2: 42, 3: 42}.itervalues() + a, b, c = {1: 42, 2: 42, 3: 42}.values() self.assertEqual((a, b, c), (42, 42, 42)) f = open(TESTFN, "w") @@ -841,7 +841,7 @@ # XXX For a more thorough test, see towards the end of: # http://mail.python.org/pipermail/python-dev/2002-July/026512_html a = {1:1, 2:2, 0:0, 4:4, 3:3} - for b in iter(a), a.iterkeys(), a.iteritems(), a.itervalues(): + for b in iter(a), a.keys(), a.items(), a.values(): b = iter(a) self.assertEqual(len(list(b)), 5) self.assertEqual(list(b), []) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_iterlen.py --- a/Lib/test/test_iterlen.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_iterlen.py Sun Feb 11 06:12:03 2007 +0000 @@ -139,14 +139,14 @@ def setUp(self): d = dict.fromkeys(xrange(n)) - self.it = d.iteritems() + self.it = d.items() self.mutate = d.popitem class TestDictValues(TestTemporarilyImmutable): def setUp(self): d = dict.fromkeys(xrange(n)) - self.it = d.itervalues() + self.it = d.values() self.mutate = d.popitem class TestSet(TestTemporarilyImmutable): diff -r f229645d607d -r f340cb045bf9 Lib/test/test_itertools.py --- a/Lib/test/test_itertools.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_itertools.py Sun Feb 11 06:12:03 2007 +0000 @@ -790,7 +790,7 @@ >>> from operator import itemgetter >>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3) ->>> di = sorted(sorted(d.iteritems()), key=itemgetter(1)) +>>> di = sorted(sorted(d.items()), key=itemgetter(1)) >>> for k, g in groupby(di, itemgetter(1)): ... print(k, map(itemgetter(0), g)) ... @@ -823,7 +823,7 @@ ... return imap(function, count()) >>> def iteritems(mapping): -... return izip(mapping.iterkeys(), mapping.itervalues()) +... return izip(mapping.keys(), mapping.values()) >>> def nth(iterable, n): ... "Returns the nth item" diff -r f229645d607d -r f340cb045bf9 Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_mailbox.py Sun Feb 11 06:12:03 2007 +0000 @@ -24,7 +24,7 @@ # Inspect a mailbox.Message representation of the sample message self.assert_(isinstance(msg, email.message.Message)) self.assert_(isinstance(msg, mailbox.Message)) - for key, value in _sample_headers.iteritems(): + for key, value in _sample_headers.items(): self.assert_(value in msg.get_all(key)) self.assert_(msg.is_multipart()) self.assert_(len(msg.get_payload()) == len(_sample_payloads)) @@ -174,7 +174,7 @@ def test_iterkeys(self): # Get keys using iterkeys() - self._check_iteration(self._box.iterkeys, do_keys=True, do_values=False) + self._check_iteration(self._box.keys, do_keys=True, do_values=False) def test_keys(self): # Get keys using keys() @@ -182,7 +182,7 @@ def test_itervalues(self): # Get values using itervalues() - self._check_iteration(self._box.itervalues, do_keys=False, + self._check_iteration(self._box.values, do_keys=False, do_values=True) def test_iter(self): @@ -196,7 +196,7 @@ def test_iteritems(self): # Get keys and values using iteritems() - self._check_iteration(self._box.iteritems, do_keys=True, + self._check_iteration(self._box.items, do_keys=True, do_values=True) def test_items(self): @@ -424,12 +424,12 @@ self.assertRaises(NotImplementedError, lambda: box.__delitem__('')) self.assertRaises(NotImplementedError, lambda: box.discard('')) self.assertRaises(NotImplementedError, lambda: box.__setitem__('', '')) - self.assertRaises(NotImplementedError, lambda: box.iterkeys()) + self.assertRaises(NotImplementedError, lambda: box.keys()) self.assertRaises(NotImplementedError, lambda: box.keys()) - self.assertRaises(NotImplementedError, lambda: box.itervalues().next()) + self.assertRaises(NotImplementedError, lambda: box.values().next()) self.assertRaises(NotImplementedError, lambda: box.__iter__().next()) self.assertRaises(NotImplementedError, lambda: box.values()) - self.assertRaises(NotImplementedError, lambda: box.iteritems().next()) + self.assertRaises(NotImplementedError, lambda: box.items().next()) self.assertRaises(NotImplementedError, lambda: box.items()) self.assertRaises(NotImplementedError, lambda: box.get('')) self.assertRaises(NotImplementedError, lambda: box.__getitem__('')) @@ -709,7 +709,7 @@ mtime = os.path.getmtime(self._path) self._box = self._factory(self._path) self.assert_(len(self._box) == 3) - for key in self._box.iterkeys(): + for key in self._box.keys(): self.assert_(self._box.get_string(key) in values) self._box.close() self.assert_(mtime == os.path.getmtime(self._path)) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_mhlib.py --- a/Lib/test/test_mhlib.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_mhlib.py Sun Feb 11 06:12:03 2007 +0000 @@ -46,7 +46,7 @@ return r def writeProfile(dict): - contents = [ "%s: %s\n" % (k, v) for k, v in dict.iteritems() ] + contents = [ "%s: %s\n" % (k, v) for k, v in dict.items() ] writeFile(_mhprofile, "".join(contents)) def writeContext(folder): @@ -61,7 +61,7 @@ def writeMessage(folder, n, headers, body): folder = normF(folder) - headers = "".join([ "%s: %s\n" % (k, v) for k, v in headers.iteritems() ]) + headers = "".join([ "%s: %s\n" % (k, v) for k, v in headers.items() ]) contents = "%s\n%s\n" % (headers,body) mkdirs(os.path.join(_mhpath, folder)) writeFile(os.path.join(_mhpath, folder, str(n)), contents) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_richcmp.py --- a/Lib/test/test_richcmp.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_richcmp.py Sun Feb 11 06:12:03 2007 +0000 @@ -131,7 +131,7 @@ self.checkequal("gt", a, b, [False, False, False, True, True ]) self.checkequal("ge", a, b, [False, False, True, True, True ]) - for ops in opmap.itervalues(): + for ops in opmap.values(): for op in ops: # calls __bool__, which should fail self.assertRaises(TypeError, bool, op(a, b)) @@ -150,7 +150,7 @@ continue # the combination int, int is useless ta = typea(a) tb = typeb(b) - for ops in opmap.itervalues(): + for ops in opmap.values(): for op in ops: realoutcome = op(a, b) testoutcome = op(ta, tb) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_site.py --- a/Lib/test/test_site.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_site.py Sun Feb 11 06:12:03 2007 +0000 @@ -204,7 +204,7 @@ if sys.platform == "win32": import locale if locale.getdefaultlocale()[1].startswith('cp'): - for value in encodings.aliases.aliases.itervalues(): + for value in encodings.aliases.aliases.values(): if value == "mbcs": break else: diff -r f229645d607d -r f340cb045bf9 Lib/test/test_support.py --- a/Lib/test/test_support.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_support.py Sun Feb 11 06:12:03 2007 +0000 @@ -239,8 +239,7 @@ def sortdict(dict): "Like repr(dict), but in sorted order." - items = dict.items() - items.sort() + items = sorted(dict.items()) reprpairs = ["%r: %r" % pair for pair in items] withcommas = ", ".join(reprpairs) return "{%s}" % withcommas @@ -305,7 +304,7 @@ return self def __exit__(self, *ignore_exc): - for envvar, value in self._reset.iteritems(): + for envvar, value in self._reset.items(): self._environ[envvar] = value for unset in self._unset: del self._environ[unset] diff -r f229645d607d -r f340cb045bf9 Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_urllib2.py Sun Feb 11 06:12:03 2007 +0000 @@ -90,8 +90,7 @@ >>> r.header_items() [('Spam-eggs', 'blah')] >>> r.add_header("Foo-Bar", "baz") - >>> items = r.header_items() - >>> items.sort() + >>> items = sorted(r.header_items()) >>> items [('Foo-bar', 'baz'), ('Spam-eggs', 'blah')] @@ -235,7 +234,7 @@ class MockHeaders(dict): def getheaders(self, name): - return self.values() + return list(self.values()) class MockResponse(StringIO.StringIO): def __init__(self, code, msg, headers, data, url=None): diff -r f229645d607d -r f340cb045bf9 Lib/test/test_userdict.py --- a/Lib/test/test_userdict.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_userdict.py Sun Feb 11 06:12:03 2007 +0000 @@ -208,7 +208,7 @@ if other is not None: for (key, value) in other: self[key] = value - for (key, value) in kwargs.iteritems(): + for (key, value) in kwargs.items(): self[key] = value def __getitem__(self, key): try: @@ -234,7 +234,7 @@ return list(self.keylist) def copy(self): d = self.__class__() - for key, value in self.iteritems(): + for key, value in self.items(): d[key] = value return d @classmethod @@ -278,13 +278,13 @@ self.assertEqual(len(s), 2) # iteritems - self.assertEqual(list(s.iteritems()), [(10,'ten'), (30, 'thirty')]) + self.assertEqual(list(s.items()), [(10,'ten'), (30, 'thirty')]) # iterkeys - self.assertEqual(list(s.iterkeys()), [10, 30]) + self.assertEqual(list(s.keys()), [10, 30]) # itervalues - self.assertEqual(list(s.itervalues()), ['ten', 'thirty']) + self.assertEqual(list(s.values()), ['ten', 'thirty']) # values self.assertEqual(s.values(), ['ten', 'thirty']) diff -r f229645d607d -r f340cb045bf9 Lib/test/test_uuid.py --- a/Lib/test/test_uuid.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_uuid.py Sun Feb 11 06:12:03 2007 +0000 @@ -295,7 +295,7 @@ if TestUUID.last_node: if TestUUID.last_node != node: msg = "different sources disagree on node:\n" - for s, n in TestUUID.source2node.iteritems(): + for s, n in TestUUID.source2node.items(): msg += " from source %r, node was %012x\n" % (s, n) # There's actually no reason to expect the MAC addresses # to agree across various methods -- e.g., a box may have diff -r f229645d607d -r f340cb045bf9 Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_weakref.py Sun Feb 11 06:12:03 2007 +0000 @@ -839,7 +839,7 @@ def check_iters(self, dict): # item iterator: items = dict.items() - for item in dict.iteritems(): + for item in dict.items(): items.remove(item) self.assert_(len(items) == 0, "iteritems() did not touch all items") @@ -851,13 +851,13 @@ # key iterator, via iterkeys(): keys = dict.keys() - for k in dict.iterkeys(): + for k in dict.keys(): keys.remove(k) self.assert_(len(keys) == 0, "iterkeys() did not touch all keys") # value iterator: values = dict.values() - for v in dict.itervalues(): + for v in dict.values(): values.remove(v) self.assert_(len(values) == 0, "itervalues() did not touch all values") @@ -1093,7 +1093,7 @@ ... def __init__(self, ob, callback=None, **annotations): ... super(ExtendedRef, self).__init__(ob, callback) ... self.__counter = 0 -... for k, v in annotations.iteritems(): +... for k, v in annotations.items(): ... setattr(self, k, v) ... def __call__(self): ... '''Return a pair containing the referent and the number of @@ -1104,7 +1104,7 @@ ... self.__counter += 1 ... ob = (ob, self.__counter) ... return ob -... +... >>> class A: # not in docs from here, just testing the ExtendedRef ... pass ... diff -r f229645d607d -r f340cb045bf9 Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/test/test_xmlrpc.py Sun Feb 11 06:12:03 2007 +0000 @@ -145,7 +145,7 @@ if not setdefaultencoding_existed: del sys.setdefaultencoding - items = d.items() + items = list(d.items()) if have_unicode: self.assertEquals(s, u"abc \x95") self.assert_(isinstance(s, unicode)) diff -r f229645d607d -r f340cb045bf9 Lib/threading.py --- a/Lib/threading.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/threading.py Sun Feb 11 06:12:03 2007 +0000 @@ -707,7 +707,7 @@ def enumerate(): _active_limbo_lock.acquire() - active = _active.values() + _limbo.values() + active = list(_active.values()) + list(_limbo.values()) _active_limbo_lock.release() return active diff -r f229645d607d -r f340cb045bf9 Lib/token.py --- a/Lib/token.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/token.py Sun Feb 11 06:12:03 2007 +0000 @@ -68,7 +68,7 @@ #--end constants-- tok_name = {} -for _name, _value in globals().items(): +for _name, _value in list(globals().items()): if type(_value) is type(0): tok_name[_value] = _name diff -r f229645d607d -r f340cb045bf9 Lib/trace.py --- a/Lib/trace.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/trace.py Sun Feb 11 06:12:03 2007 +0000 @@ -282,7 +282,7 @@ # accumulate summary info, if needed sums = {} - for filename, count in per_file.iteritems(): + for filename, count in per_file.items(): # skip some "files" we don't care about... if filename == "": continue diff -r f229645d607d -r f340cb045bf9 Lib/urllib2.py --- a/Lib/urllib2.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/urllib2.py Sun Feb 11 06:12:03 2007 +0000 @@ -281,7 +281,7 @@ def header_items(self): hdrs = self.unredirected_hdrs.copy() hdrs.update(self.headers) - return hdrs.items() + return list(hdrs.items()) class OpenerDirector: def __init__(self): @@ -710,7 +710,7 @@ domains = self.passwd.get(realm, {}) for default_port in True, False: reduced_authuri = self.reduce_uri(authuri, default_port) - for uris, authinfo in domains.iteritems(): + for uris, authinfo in domains.items(): for uri in uris: if self.is_suburi(uri, reduced_authuri): return authinfo @@ -1318,21 +1318,21 @@ # first check for old ones t = time.time() if self.soonest <= t: - for k, v in self.timeout.items(): + for k, v in list(self.timeout.items()): if v < t: self.cache[k].close() del self.cache[k] del self.timeout[k] - self.soonest = min(self.timeout.values()) + self.soonest = min(list(self.timeout.values())) # then check the size if len(self.cache) == self.max_conns: - for k, v in self.timeout.items(): + for k, v in list(self.timeout.items()): if v == self.soonest: del self.cache[k] del self.timeout[k] break - self.soonest = min(self.timeout.values()) + self.soonest = min(list(self.timeout.values())) class GopherHandler(BaseHandler): def gopher_open(self, req): diff -r f229645d607d -r f340cb045bf9 Lib/weakref.py --- a/Lib/weakref.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/weakref.py Sun Feb 11 06:12:03 2007 +0000 @@ -100,16 +100,16 @@ return L def iteritems(self): - for wr in self.data.itervalues(): + for wr in self.data.values(): value = wr() if value is not None: yield wr.key, value def iterkeys(self): - return self.data.iterkeys() + return self.data.keys() def __iter__(self): - return self.data.iterkeys() + return self.data.keys() def itervaluerefs(self): """Return an iterator that yields the weak references to the values. @@ -121,10 +121,10 @@ keep the values around longer than needed. """ - return self.data.itervalues() + return self.data.values() def itervalues(self): - for wr in self.data.itervalues(): + for wr in self.data.values(): obj = wr() if obj is not None: yield obj @@ -268,7 +268,7 @@ return L def iteritems(self): - for wr, value in self.data.iteritems(): + for wr, value in self.data.items(): key = wr() if key is not None: yield key, value @@ -283,19 +283,19 @@ keep the keys around longer than needed. """ - return self.data.iterkeys() + return self.data.keys() def iterkeys(self): - for wr in self.data.iterkeys(): + for wr in self.data.keys(): obj = wr() if obj is not None: yield obj def __iter__(self): - return self.iterkeys() + return self.keys() def itervalues(self): - return self.data.itervalues() + return self.data.values() def keyrefs(self): """Return a list of weak references to the keys. diff -r f229645d607d -r f340cb045bf9 Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py Sat Feb 10 22:53:17 2007 +0000 +++ b/Lib/xml/etree/ElementTree.py Sun Feb 11 06:12:03 2007 +0000 @@ -645,7 +645,7 @@ elif tag is ProcessingInstruction: file.write("" % _escape_cdata(node.text, encoding)) else: - items = node.items() + items = list(node.items()) xmlns_items = [] # new namespaces in this scope try: if isinstance(tag, QName) or tag[:1] == "{": diff -r f229645d607d -r f340cb045bf9 Misc/NEWS --- a/Misc/NEWS Sat Feb 10 22:53:17 2007 +0000 +++ b/Misc/NEWS Sun Feb 11 06:12:03 2007 +0000 @@ -36,6 +36,9 @@ Core and Builtins ----------------- +- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone; + and .keys(), .items(), .values() return dict views. + - PEP 3105: print is now a function. Also (not in the PEP) the 'softspace' attribute of files is now gone (since print() doesn't use it). A side effect of this change is that you can get incomplete diff -r f229645d607d -r f340cb045bf9 Modules/cPickle.c --- a/Modules/cPickle.c Sat Feb 10 22:53:17 2007 +0000 +++ b/Modules/cPickle.c Sun Feb 11 06:12:03 2007 +0000 @@ -1752,7 +1752,7 @@ int res = -1; char s[3]; int len; - PyObject *iter; + PyObject *items, *iter; if (self->fast && !fast_save_enter(self, args)) goto finally; @@ -1784,7 +1784,11 @@ goto finally; /* Materialize the dict items. */ - iter = PyObject_CallMethod(args, "iteritems", "()"); + items = PyObject_CallMethod(args, "items", "()"); + if (items == NULL) + goto finally; + iter = PyObject_GetIter(items); + Py_DECREF(items); if (iter == NULL) goto finally; res = batch_dict(self, iter); diff -r f229645d607d -r f340cb045bf9 Modules/collectionsmodule.c --- a/Modules/collectionsmodule.c Sat Feb 10 22:53:17 2007 +0000 +++ b/Modules/collectionsmodule.c Sun Feb 11 06:12:03 2007 +0000 @@ -1140,6 +1140,7 @@ */ PyObject *args; PyObject *items; + PyObject *iteritems; PyObject *result; if (dd->default_factory == NULL || dd->default_factory == Py_None) args = PyTuple_New(0); @@ -1147,14 +1148,20 @@ args = PyTuple_Pack(1, dd->default_factory); if (args == NULL) return NULL; - items = PyObject_CallMethod((PyObject *)dd, "iteritems", "()"); + items = PyObject_CallMethod((PyObject *)dd, "items", "()"); if (items == NULL) { Py_DECREF(args); return NULL; } + iteritems = PyObject_GetIter(items); + Py_DECREF(items); + if (iteritems == NULL) { + Py_DECREF(args); + return NULL; + } result = PyTuple_Pack(5, dd->dict.ob_type, args, - Py_None, Py_None, items); - Py_DECREF(items); + Py_None, Py_None, iteritems); + Py_DECREF(iteritems); Py_DECREF(args); return result; } diff -r f229645d607d -r f340cb045bf9 Objects/abstract.c --- a/Objects/abstract.c Sat Feb 10 22:53:17 2007 +0000 +++ b/Objects/abstract.c Sun Feb 11 06:12:03 2007 +0000 @@ -1657,6 +1657,54 @@ return 0; } +PyObject * +PyMapping_Keys(PyObject *o) +{ + PyObject *keys; + PyObject *fast; + + if (PyDict_CheckExact(o)) + return PyDict_Keys(o); + keys = PyObject_CallMethod(o, "keys", NULL); + if (keys == NULL) + return NULL; + fast = PySequence_Fast(keys, "o.keys() are not iterable"); + Py_DECREF(keys); + return fast; +} + +PyObject * +PyMapping_Items(PyObject *o) +{ + PyObject *items; + PyObject *fast; + + if (PyDict_CheckExact(o)) + return PyDict_Items(o); + items = PyObject_CallMethod(o, "items", NULL); + if (items == NULL) + return NULL; + fast = PySequence_Fast(items, "o.items() are not iterable"); + Py_DECREF(items); + return fast; +} + +PyObject * +PyMapping_Values(PyObject *o) +{ + PyObject *values; + PyObject *fast; + + if (PyDict_CheckExact(o)) + return PyDict_Values(o); + values = PyObject_CallMethod(o, "values", NULL); + if (values == NULL) + return NULL; + fast = PySequence_Fast(values, "o.values() are not iterable"); + Py_DECREF(values); + return fast; +} + /* Operations on callable objects */ /* XXX PyCallable_Check() is in object.c */ diff -r f229645d607d -r f340cb045bf9 Objects/dictobject.c --- a/Objects/dictobject.c Sat Feb 10 22:53:17 2007 +0000 +++ b/Objects/dictobject.c Sun Feb 11 06:12:03 2007 +0000 @@ -1760,6 +1760,7 @@ extern PyTypeObject PyDictIterItem_Type; /* Forward */ static PyObject *dictiter_new(dictobject *, PyTypeObject *); +#if 0 static PyObject * dict_iterkeys(dictobject *dict) { @@ -1777,6 +1778,7 @@ { return dictiter_new(dict, &PyDictIterItem_Type); } +#endif PyDoc_STRVAR(contains__doc__, @@ -1798,6 +1800,7 @@ "D.popitem() -> (k, v), remove and return some (key, value) pair as a\n\ 2-tuple; but raise KeyError if D is empty"); +#if 0 PyDoc_STRVAR(keys__doc__, "D.keys() -> list of D's keys"); @@ -1806,6 +1809,7 @@ PyDoc_STRVAR(values__doc__, "D.values() -> list of D's values"); +#endif PyDoc_STRVAR(update__doc__, "D.update(E, **F) -> None. Update D from E and F: for k in E: D[k] = E[k]\ @@ -1821,6 +1825,7 @@ PyDoc_STRVAR(copy__doc__, "D.copy() -> a shallow copy of D"); +#if 0 PyDoc_STRVAR(iterkeys__doc__, "D.iterkeys() -> an iterator over the keys of D"); @@ -1829,6 +1834,7 @@ PyDoc_STRVAR(iteritems__doc__, "D.iteritems() -> an iterator over the (key, value) items of D"); +#endif /* Forward */ static PyObject *dictkeys_new(PyObject *); @@ -1852,18 +1858,20 @@ pop__doc__}, {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, popitem__doc__}, +#if 0 {"keys", (PyCFunction)dict_keys, METH_NOARGS, keys__doc__}, - {"KEYS", (PyCFunction)dictkeys_new, METH_NOARGS, - KEYS__doc__}, - {"ITEMS", (PyCFunction)dictitems_new, METH_NOARGS, - ITEMS__doc__}, - {"VALUES", (PyCFunction)dictvalues_new, METH_NOARGS, - VALUES__doc__}, {"items", (PyCFunction)dict_items, METH_NOARGS, items__doc__}, {"values", (PyCFunction)dict_values, METH_NOARGS, values__doc__}, +#endif + {"keys", (PyCFunction)dictkeys_new, METH_NOARGS, + KEYS__doc__}, + {"items", (PyCFunction)dictitems_new, METH_NOARGS, + ITEMS__doc__}, + {"values", (PyCFunction)dictvalues_new, METH_NOARGS, + VALUES__doc__}, {"update", (PyCFunction)dict_update, METH_VARARGS | METH_KEYWORDS, update__doc__}, {"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS | METH_CLASS, @@ -1872,12 +1880,14 @@ clear__doc__}, {"copy", (PyCFunction)dict_copy, METH_NOARGS, copy__doc__}, +#if 0 {"iterkeys", (PyCFunction)dict_iterkeys, METH_NOARGS, iterkeys__doc__}, {"itervalues", (PyCFunction)dict_itervalues, METH_NOARGS, itervalues__doc__}, {"iteritems", (PyCFunction)dict_iteritems, METH_NOARGS, iteritems__doc__}, +#endif {NULL, NULL} /* sentinel */ }; diff -r f229645d607d -r f340cb045bf9 Objects/typeobject.c --- a/Objects/typeobject.c Sat Feb 10 22:53:17 2007 +0000 +++ b/Objects/typeobject.c Sun Feb 11 06:12:03 2007 +0000 @@ -2601,7 +2601,11 @@ Py_INCREF(dictitems); } else { - dictitems = PyObject_CallMethod(obj, "iteritems", ""); + PyObject *items = PyObject_CallMethod(obj, "items", ""); + if (items == NULL) + goto end; + dictitems = PyObject_GetIter(items); + Py_DECREF(items); if (dictitems == NULL) goto end; }