classobject.c moduleobject.c stdwinmodule.c xxobject.c:

raise AttributeError, not KeyError, when attribute deletion fails.
sunaudiodevmodule.c: check for deletion before calling setmember.
This commit is contained in:
Guido van Rossum 1992-09-04 09:45:18 +00:00
parent 9a4e3fc56a
commit 94472a0374
5 changed files with 56 additions and 15 deletions

View 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);
}