mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
This commit is contained in:
parent
882fcede83
commit
72d3cc94cd
15 changed files with 116 additions and 119 deletions
|
@ -372,33 +372,27 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
static PyObject*
|
||||
get_attrib_from_keywords(PyObject *kwds)
|
||||
{
|
||||
PyObject *attrib_str = PyUnicode_FromString("attrib");
|
||||
if (attrib_str == NULL) {
|
||||
PyObject *attrib;
|
||||
if (PyDict_PopString(kwds, "attrib", &attrib) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *attrib = PyDict_GetItemWithError(kwds, attrib_str);
|
||||
|
||||
if (attrib) {
|
||||
/* If attrib was found in kwds, copy its value and remove it from
|
||||
* kwds
|
||||
*/
|
||||
if (!PyDict_Check(attrib)) {
|
||||
Py_DECREF(attrib_str);
|
||||
PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s",
|
||||
Py_TYPE(attrib)->tp_name);
|
||||
Py_DECREF(attrib);
|
||||
return NULL;
|
||||
}
|
||||
attrib = PyDict_Copy(attrib);
|
||||
if (attrib && PyDict_DelItem(kwds, attrib_str) < 0) {
|
||||
Py_SETREF(attrib, NULL);
|
||||
}
|
||||
Py_SETREF(attrib, PyDict_Copy(attrib));
|
||||
}
|
||||
else if (!PyErr_Occurred()) {
|
||||
else {
|
||||
attrib = PyDict_New();
|
||||
}
|
||||
|
||||
Py_DECREF(attrib_str);
|
||||
|
||||
if (attrib != NULL && PyDict_Update(attrib, kwds) < 0) {
|
||||
Py_DECREF(attrib);
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue