remove unnecessary braces and indentation
This commit is contained in:
parent
277b975260
commit
99e96f2bb0
|
@ -2404,74 +2404,21 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
/* first handle args, if any */
|
/* first handle args, if any */
|
||||||
if (len < 0) /* PyObject_Size raised an exception. */
|
if (len < 0) /* PyObject_Size raised an exception. */
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (len > 1) {
|
|
||||||
|
if (len > 1) {
|
||||||
char *msg = "update() takes at most 1 positional argument (%d given)";
|
char *msg = "update() takes at most 1 positional argument (%d given)";
|
||||||
PyErr_Format(PyExc_TypeError, msg, len);
|
PyErr_Format(PyExc_TypeError, msg, len);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (len == 1) {
|
|
||||||
PyObject *other = PyTuple_GET_ITEM(args, 0); /* borrowed reference */
|
|
||||||
if (other == NULL)
|
|
||||||
return NULL;
|
|
||||||
Py_INCREF(other);
|
|
||||||
if (PyObject_HasAttrString(other, "items")) { /* never fails */
|
|
||||||
PyObject *items = PyMapping_Items(other);
|
|
||||||
Py_DECREF(other);
|
|
||||||
if (items == NULL)
|
|
||||||
return NULL;
|
|
||||||
res = mutablemapping_add_pairs(self, items);
|
|
||||||
Py_DECREF(items);
|
|
||||||
if (res == -1)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else if (PyObject_HasAttrString(other, "keys")) { /* never fails */
|
|
||||||
PyObject *keys, *iterator, *key;
|
|
||||||
keys = PyObject_CallMethod(other, "keys", NULL);
|
|
||||||
if (keys == NULL) {
|
|
||||||
Py_DECREF(other);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
iterator = PyObject_GetIter(keys);
|
|
||||||
Py_DECREF(keys);
|
|
||||||
if (iterator == NULL) {
|
|
||||||
Py_DECREF(other);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
while (res == 0 && (key = PyIter_Next(iterator))) {
|
|
||||||
PyObject *value = PyObject_GetItem(other, key);
|
|
||||||
if (value != NULL) {
|
|
||||||
res = PyObject_SetItem(self, key, value);
|
|
||||||
Py_DECREF(value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res = -1;
|
|
||||||
}
|
|
||||||
Py_DECREF(key);
|
|
||||||
}
|
|
||||||
Py_DECREF(other);
|
|
||||||
Py_DECREF(iterator);
|
|
||||||
if (res != 0 || PyErr_Occurred())
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res = mutablemapping_add_pairs(self, other);
|
|
||||||
Py_DECREF(other);
|
|
||||||
if (res != 0)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now handle kwargs */
|
|
||||||
len = (kwargs != NULL) ? PyObject_Size(kwargs) : 0;
|
PyObject *other = PyTuple_GET_ITEM(args, 0); /* borrowed reference */
|
||||||
if (len < 0) /* PyObject_Size raised an exception. */
|
if (other == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (len > 0) {
|
Py_INCREF(other);
|
||||||
PyObject *items;
|
if (PyObject_HasAttrString(other, "items")) { /* never fails */
|
||||||
if (!PyMapping_Check(kwargs)) {
|
PyObject *items = PyMapping_Items(other);
|
||||||
PyErr_SetString(PyExc_TypeError, "expected mapping for kwargs");
|
Py_DECREF(other);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
items = PyMapping_Items(kwargs);
|
|
||||||
if (items == NULL)
|
if (items == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
res = mutablemapping_add_pairs(self, items);
|
res = mutablemapping_add_pairs(self, items);
|
||||||
|
@ -2479,6 +2426,58 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
else if (PyObject_HasAttrString(other, "keys")) { /* never fails */
|
||||||
|
PyObject *keys, *iterator, *key;
|
||||||
|
keys = PyObject_CallMethod(other, "keys", NULL);
|
||||||
|
if (keys == NULL) {
|
||||||
|
Py_DECREF(other);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
iterator = PyObject_GetIter(keys);
|
||||||
|
Py_DECREF(keys);
|
||||||
|
if (iterator == NULL) {
|
||||||
|
Py_DECREF(other);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
while (res == 0 && (key = PyIter_Next(iterator))) {
|
||||||
|
PyObject *value = PyObject_GetItem(other, key);
|
||||||
|
if (value != NULL) {
|
||||||
|
res = PyObject_SetItem(self, key, value);
|
||||||
|
Py_DECREF(value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res = -1;
|
||||||
|
}
|
||||||
|
Py_DECREF(key);
|
||||||
|
}
|
||||||
|
Py_DECREF(other);
|
||||||
|
Py_DECREF(iterator);
|
||||||
|
if (res != 0 || PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res = mutablemapping_add_pairs(self, other);
|
||||||
|
Py_DECREF(other);
|
||||||
|
if (res != 0)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now handle kwargs */
|
||||||
|
len = (kwargs != NULL) ? PyObject_Size(kwargs) : 0;
|
||||||
|
if (len < 0) /* PyObject_Size raised an exception. */
|
||||||
|
return NULL;
|
||||||
|
PyObject *items;
|
||||||
|
if (!PyMapping_Check(kwargs)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "expected mapping for kwargs");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
items = PyMapping_Items(kwargs);
|
||||||
|
if (items == NULL)
|
||||||
|
return NULL;
|
||||||
|
res = mutablemapping_add_pairs(self, items);
|
||||||
|
Py_DECREF(items);
|
||||||
|
if (res == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue