summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-02-25 15:59:46 (GMT)
committerGitHub <noreply@github.com>2019-02-25 15:59:46 (GMT)
commita24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch)
tree55aa5a700e08e3ba27b0361df2b1043be5c4701a /Modules/itertoolsmodule.c
parenta180b007d96fe68b32f11dec720fbd0cd5b6758a (diff)
downloadcpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.zip
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.bz2
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 581ae2c..c589dd1 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -4418,6 +4418,7 @@ static PyTypeObject ziplongest_type;
static PyObject *
zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
+ _Py_IDENTIFIER(fillvalue);
ziplongestobject *lz;
Py_ssize_t i;
PyObject *ittuple; /* tuple of iterators */
@@ -4426,10 +4427,15 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_ssize_t tuplesize;
if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) {
- fillvalue = PyDict_GetItemString(kwds, "fillvalue");
- if (fillvalue == NULL || PyDict_GET_SIZE(kwds) > 1) {
- PyErr_SetString(PyExc_TypeError,
- "zip_longest() got an unexpected keyword argument");
+ fillvalue = NULL;
+ if (PyDict_GET_SIZE(kwds) == 1) {
+ fillvalue = _PyDict_GetItemIdWithError(kwds, &PyId_fillvalue);
+ }
+ if (fillvalue == NULL) {
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "zip_longest() got an unexpected keyword argument");
+ }
return NULL;
}
}