]> granicus.if.org Git - python/commitdiff
Issue #17989: element_setattro returned incorrect error value.
authorEli Bendersky <eliben@gmail.com>
Sat, 18 May 2013 14:52:34 +0000 (07:52 -0700)
committerEli Bendersky <eliben@gmail.com>
Sat, 18 May 2013 14:52:34 +0000 (07:52 -0700)
This caused an exception to be raised later than expected.

Modules/_elementtree.c

index 86fdd2f1db9dbc1967da5ec6a4db11a336b8d9c5..9caef99ea6a6185d8030122ce51903400284301a 100644 (file)
@@ -1808,17 +1808,16 @@ element_getattro(ElementObject* self, PyObject* nameobj)
     return res;
 }
 
-static PyObject*
+static int
 element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
 {
     char *name = "";
     if (PyUnicode_Check(nameobj))
         name = _PyUnicode_AsString(nameobj);
 
-    if (name == NULL)
-        return NULL;
-
-    if (strcmp(name, "tag") == 0) {
+    if (name == NULL) {
+        return -1;
+    } else if (strcmp(name, "tag") == 0) {
         Py_DECREF(self->tag);
         self->tag = value;
         Py_INCREF(self->tag);
@@ -1837,11 +1836,12 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
         self->extra->attrib = value;
         Py_INCREF(self->extra->attrib);
     } else {
-        PyErr_SetString(PyExc_AttributeError, name);
-        return NULL;
+        PyErr_SetString(PyExc_AttributeError,
+            "Can't set arbitraty attributes on Element");
+        return -1;
     }
 
-    return NULL;
+    return 0;
 }
 
 static PySequenceMethods element_as_sequence = {