summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-02-11 06:12:03 (GMT)
committerGuido van Rossum <guido@python.org>2007-02-11 06:12:03 (GMT)
commitcc2b0161257495f859200bce0aea3ed7e646feb3 (patch)
treeba09aba0de6447bef5be59b43fb86d17d760833d /Objects/abstract.c
parent4e66dfcdc495218ad5f98b12ad6b4b2b05630ab0 (diff)
downloadcpython-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 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 8405782..4e5838f 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1657,6 +1657,54 @@ PyMapping_HasKey(PyObject *o, PyObject *key)
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 */