summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-04 09:45:18 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-04 09:45:18 (GMT)
commit94472a0374f68fc7c746671eb87dc32253b02f05 (patch)
tree2771e08e0f6355403716eac5d9db818643f7d732 /Objects
parent9a4e3fc56a2bacc7af884117c53b37fdf104daa2 (diff)
downloadcpython-94472a0374f68fc7c746671eb87dc32253b02f05.zip
cpython-94472a0374f68fc7c746671eb87dc32253b02f05.tar.gz
cpython-94472a0374f68fc7c746671eb87dc32253b02f05.tar.bz2
classobject.c moduleobject.c stdwinmodule.c xxobject.c:
raise AttributeError, not KeyError, when attribute deletion fails. sunaudiodevmodule.c: check for deletion before calling setmember.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c18
-rw-r--r--Objects/moduleobject.c11
-rw-r--r--Objects/xxobject.c9
3 files changed, 29 insertions, 9 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 19f887c..514869c 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -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);
}
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index bbe927c..aedba35 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -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);
}
diff --git a/Objects/xxobject.c b/Objects/xxobject.c
index 7ab7a73..8471893 100644
--- a/Objects/xxobject.c
+++ b/Objects/xxobject.c
@@ -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);
}