[Python-checkins] cpython: Simplify the code of get_attrib_from_keywords somewhat.

eli.bendersky python-checkins at python.org
Mon Apr 22 14:52:40 CEST 2013


http://hg.python.org/cpython/rev/c9674421d78e
changeset:   83494:c9674421d78e
user:        Eli Bendersky <eliben at gmail.com>
date:        Mon Apr 22 05:52:16 2013 -0700
summary:
  Simplify the code of get_attrib_from_keywords somewhat.

files:
  Modules/_elementtree.c |  14 +++++---------
  1 files changed, 5 insertions(+), 9 deletions(-)


diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -278,29 +278,25 @@
 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;
 }
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list