mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Don't allow assignment to attributes named __*__
This commit is contained in:
parent
5113f5fd34
commit
8dd79cf788
1 changed files with 16 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
||||||
Netherlands.
|
Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
@ -122,6 +122,13 @@ class_setattr(op, name, v)
|
||||||
char *name;
|
char *name;
|
||||||
object *v;
|
object *v;
|
||||||
{
|
{
|
||||||
|
if (name[0] == '_' && name[1] == '_') {
|
||||||
|
int n = strlen(name);
|
||||||
|
if (name[n-1] == '_' && name[n-2] == '_') {
|
||||||
|
err_setstr(TypeError, "read-only special attribute");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return dictremove(op->cl_methods, name);
|
return dictremove(op->cl_methods, name);
|
||||||
else
|
else
|
||||||
|
@ -226,6 +233,13 @@ instance_setattr(inst, name, v)
|
||||||
char *name;
|
char *name;
|
||||||
object *v;
|
object *v;
|
||||||
{
|
{
|
||||||
|
if (name[0] == '_' && name[1] == '_') {
|
||||||
|
int n = strlen(name);
|
||||||
|
if (name[n-1] == '_' && name[n-2] == '_') {
|
||||||
|
err_setstr(TypeError, "read-only special attribute");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return dictremove(inst->in_attr, name);
|
return dictremove(inst->in_attr, name);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue