[Python-checkins] cpython (merge 3.3 -> default): Issue #17989: element_setattro returned incorrect error value.

eli.bendersky python-checkins at python.org
Sat May 18 16:53:54 CEST 2013


http://hg.python.org/cpython/rev/b111ae4f83ef
changeset:   83825:b111ae4f83ef
parent:      83823:1b760f926846
parent:      83824:9682241dc8fc
user:        Eli Bendersky <eliben at gmail.com>
date:        Sat May 18 07:53:47 2013 -0700
summary:
  Issue #17989: element_setattro returned incorrect error value.

This caused an exception to be raised later than expected.

files:
  Modules/_elementtree.c |  16 ++++++++--------
  1 files changed, 8 insertions(+), 8 deletions(-)


diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1768,17 +1768,16 @@
     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);
@@ -1797,11 +1796,12 @@
         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 = {

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


More information about the Python-checkins mailing list