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 /Modules | |
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 'Modules')
-rw-r--r-- | Modules/cPickle.c | 8 | ||||
-rw-r--r-- | Modules/collectionsmodule.c | 13 |
2 files changed, 16 insertions, 5 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 98ab500..ad2b91f 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -1752,7 +1752,7 @@ save_dict(Picklerobject *self, PyObject *args) 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 @@ save_dict(Picklerobject *self, PyObject *args) 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 --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index 9fff7f0..f75e1a3 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -1140,6 +1140,7 @@ defdict_reduce(defdictobject *dd) */ 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 @@ defdict_reduce(defdictobject *dd) 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; } - result = PyTuple_Pack(5, dd->dict.ob_type, args, - Py_None, Py_None, items); + 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, iteritems); + Py_DECREF(iteritems); Py_DECREF(args); return result; } |