diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-03-07 09:21:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 09:21:08 (GMT) |
commit | 72d3cc94cd8cae1925e7a14f297b06ac6184f916 (patch) | |
tree | df9d7a5a97a79f97065282dd8e5a89f57ea2e18b /Modules/_elementtree.c | |
parent | 882fcede83af783a834b759e4643130dc1307ee3 (diff) | |
download | cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.zip cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.gz cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.bz2 |
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index edd2f88..aaa0cad 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -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; |