mirror of
https://github.com/python/cpython.git
synced 2025-10-20 13:43:01 +00:00
Simplify the code of get_attrib_from_keywords somewhat.
This commit is contained in:
parent
ed8b86d323
commit
1859fe80c4
1 changed files with 5 additions and 9 deletions
|
@ -278,28 +278,24 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
static PyObject*
|
static PyObject*
|
||||||
get_attrib_from_keywords(PyObject *kwds)
|
get_attrib_from_keywords(PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *attrib_str = PyUnicode_FromString("attrib");
|
const char* ATTRIB_KEY = "attrib";
|
||||||
PyObject *attrib = PyDict_GetItem(kwds, attrib_str);
|
PyObject *attrib = PyDict_GetItemString(kwds, ATTRIB_KEY);
|
||||||
|
|
||||||
if (attrib) {
|
if (attrib) {
|
||||||
/* If attrib was found in kwds, copy its value and remove it from
|
/* If attrib was found in kwds, copy its value and remove it from
|
||||||
* kwds
|
* kwds
|
||||||
*/
|
*/
|
||||||
if (!PyDict_Check(attrib)) {
|
if (!PyDict_Check(attrib)) {
|
||||||
Py_DECREF(attrib_str);
|
|
||||||
PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s",
|
PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s",
|
||||||
Py_TYPE(attrib)->tp_name);
|
Py_TYPE(attrib)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
attrib = PyDict_Copy(attrib);
|
attrib = PyDict_Copy(attrib);
|
||||||
PyDict_DelItem(kwds, attrib_str);
|
PyDict_DelItemString(kwds, ATTRIB_KEY);
|
||||||
} else {
|
} else {
|
||||||
attrib = PyDict_New();
|
attrib = PyDict_New();
|
||||||
}
|
}
|
||||||
|
assert(attrib);
|
||||||
Py_DECREF(attrib_str);
|
|
||||||
|
|
||||||
if (attrib)
|
|
||||||
PyDict_Update(attrib, kwds);
|
PyDict_Update(attrib, kwds);
|
||||||
return attrib;
|
return attrib;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue