]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
authorGuido van Rossum <guido@python.org>
Fri, 4 Sep 1992 09:45:18 +0000 (09:45 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 4 Sep 1992 09:45:18 +0000 (09:45 +0000)
raise AttributeError, not KeyError, when attribute deletion fails.
sunaudiodevmodule.c: check for deletion before calling setmember.

Modules/stdwinmodule.c
Modules/sunaudiodev.c
Objects/classobject.c
Objects/moduleobject.c
Objects/xxobject.c

index e33610d7d626a8745d8b1e6778b087d3c55142bc..8b3812b5f0c254b29d64ef3c5581dc2d89ab4512 100644 (file)
@@ -1051,8 +1051,13 @@ text_setattr(tp, name, v)
                if (tp->t_attr == NULL)
                        return -1;
        }
-       if (v == NULL)
-               return dictremove(tp->t_attr, name);
+       if (v == NULL) {
+               int rv = dictremove(tp->t_attr, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                               "delete non-existing text object attribute");
+               return rv;
+       }
        else
                return dictinsert(tp->t_attr, name, v);
 }
@@ -1253,8 +1258,13 @@ menu_setattr(mp, name, v)
                if (mp->m_attr == NULL)
                        return -1;
        }
-       if (v == NULL)
-               return dictremove(mp->m_attr, name);
+       if (v == NULL) {
+               int rv = dictremove(mp->m_attr, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                               "delete non-existing menu object attribute");
+               return rv;
+       }
        else
                return dictinsert(mp->m_attr, name, v);
 }
@@ -1655,8 +1665,13 @@ window_setattr(wp, name, v)
                if (wp->w_attr == NULL)
                        return -1;
        }
-       if (v == NULL)
-               return dictremove(wp->w_attr, name);
+       if (v == NULL) {
+               int rv = dictremove(wp->w_attr, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                               "delete non-existing menu object attribute");
+               return rv;
+       }
        else
                return dictinsert(wp->w_attr, name, v);
 }
index 0cf56131c6f88cb6201cea0fcc543ec35b56ae1f..d02041acbff290d63c2df07d2b05aa297b65e7bc 100644 (file)
@@ -343,6 +343,12 @@ sads_setattr(xp, name, v)
     char *name;
     object *v;
 {
+
+       if (v == NULL) {
+               err_setstr(TypeError,
+                          "can't delete sun audio status attributes");
+               return NULL;
+       }
        return setmember((char *)&xp->ai, sads_ml, name, v);
 }
 
index 19f887cd71495b7ef663817bcebe49dfdcfe45fa..514869c568d1a13c561ffe1417d957ef471637d1 100644 (file)
@@ -133,8 +133,13 @@ class_setattr(op, name, v)
                        return -1;
                }
        }
-       if (v == NULL)
-               return dictremove(op->cl_methods, name);
+       if (v == NULL) {
+               int rv = dictremove(op->cl_methods, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                                  "delete non-existing class attribute");
+               return rv;
+       }
        else
                return dictinsert(op->cl_methods, name, v);
 }
@@ -245,8 +250,13 @@ instance_setattr(inst, name, v)
                        return -1;
                }
        }
-       if (v == NULL)
-               return dictremove(inst->in_attr, name);
+       if (v == NULL) {
+               int rv = dictremove(inst->in_attr, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                                  "delete non-existing instance attribute");
+               return rv;
+       }
        else
                return dictinsert(inst->in_attr, name, v);
 }
index bbe927cf663d57e7a61cc2beb869d47fc26aff3a..aedba35bca5b8b124cb47776abbf5e661f11cd89 100644 (file)
@@ -132,11 +132,16 @@ module_setattr(m, name, v)
        object *v;
 {
        if (strcmp(name, "__dict__") == 0 || strcmp(name, "__name__") == 0) {
-               err_setstr(TypeError, "can't assign to reserved member name");
+               err_setstr(TypeError, "read-only special attribute");
                return -1;
        }
-       if (v == NULL)
-               return dictremove(m->md_dict, name);
+       if (v == NULL) {
+               int rv = dictremove(m->md_dict, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                                  "delete non-existing module attribute");
+               return rv;
+       }
        else
                return dictinsert(m->md_dict, name, v);
 }
index 7ab7a73c2484940f56671afced5c22d6faa25cdf..8471893e22ab76a3a6cb77c52e25c4b4d77fa7e0 100644 (file)
@@ -110,8 +110,13 @@ xx_setattr(xp, name, v)
                if (xp->x_attr == NULL)
                        return -1;
        }
-       if (v == NULL)
-               return dictremove(xp->x_attr, name);
+       if (v == NULL) {
+               int rv = dictremove(xp->x_attr, name);
+               if (rv < 0)
+                       err_setstr(AttributeError,
+                               "delete non-existing xx attribute");
+               return rv;
+       }
        else
                return dictinsert(xp->x_attr, name, v);
 }