bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)

This commit is contained in:
Serhiy Storchaka 2019-02-25 17:59:46 +02:00 committed by GitHub
parent a180b007d9
commit a24107b04c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 538 additions and 242 deletions

View file

@ -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;
}
}