diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-04-22 12:52:16 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-04-22 12:52:16 (GMT) |
commit | 1859fe80c424cd2c8211c90f1c46a64606cb8ccb (patch) | |
tree | cb0f7cd0609e4bb0b18071bde6904f8ba3d4fe73 /Modules/_elementtree.c | |
parent | ed8b86d323f83d546574fc7b4a6dd22579319f70 (diff) | |
download | cpython-1859fe80c424cd2c8211c90f1c46a64606cb8ccb.zip cpython-1859fe80c424cd2c8211c90f1c46a64606cb8ccb.tar.gz cpython-1859fe80c424cd2c8211c90f1c46a64606cb8ccb.tar.bz2 |
Simplify the code of get_attrib_from_keywords somewhat.
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index b05a39f..5a1ed8c 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -278,29 +278,25 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject* get_attrib_from_keywords(PyObject *kwds) { - PyObject *attrib_str = PyUnicode_FromString("attrib"); - PyObject *attrib = PyDict_GetItem(kwds, attrib_str); + const char* ATTRIB_KEY = "attrib"; + PyObject *attrib = PyDict_GetItemString(kwds, ATTRIB_KEY); 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); return NULL; } attrib = PyDict_Copy(attrib); - PyDict_DelItem(kwds, attrib_str); + PyDict_DelItemString(kwds, ATTRIB_KEY); } else { attrib = PyDict_New(); } - - Py_DECREF(attrib_str); - - if (attrib) - PyDict_Update(attrib, kwds); + assert(attrib); + PyDict_Update(attrib, kwds); return attrib; } |