diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-04-20 21:23:52 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-04-20 21:23:52 (GMT) |
commit | a154b5cea43996f69e800e59a8aa0e75095db7f4 (patch) | |
tree | db39e684f9260d0bc6ff769962b2bb37500487ed /Modules | |
parent | 52d8fb5c545804d76288ceddb89f6a5d8cba1050 (diff) | |
download | cpython-a154b5cea43996f69e800e59a8aa0e75095db7f4.zip cpython-a154b5cea43996f69e800e59a8aa0e75095db7f4.tar.gz cpython-a154b5cea43996f69e800e59a8aa0e75095db7f4.tar.bz2 |
Simplify _count_elements() in _collections
PyIter_Next() cannot return a PyExc_StopIteration: it clears this exception.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 5545d1e..8743408 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1552,12 +1552,8 @@ _count_elements(PyObject *self, PyObject *args) if (PyDict_CheckExact(mapping)) { while (1) { key = PyIter_Next(it); - if (key == NULL) { - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) - PyErr_Clear(); - else - break; - } + if (key == NULL) + break; oldval = PyDict_GetItem(mapping, key); if (oldval == NULL) { if (PyDict_SetItem(mapping, key, one) == -1) @@ -1575,12 +1571,8 @@ _count_elements(PyObject *self, PyObject *args) } else { while (1) { key = PyIter_Next(it); - if (key == NULL) { - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) - PyErr_Clear(); - else - break; - } + if (key == NULL) + break; oldval = PyObject_GetItem(mapping, key); if (oldval == NULL) { if (!PyErr_Occurred() || !PyErr_ExceptionMatches(PyExc_KeyError)) |