mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
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:
parent
9a4e3fc56a
commit
94472a0374
5 changed files with 56 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue