Mercurial > cpython-lru_cache-weakref
diff Objects/classobject.c @ 791:77ee9b222fdb legacy-trunk
Don't allow assignment to attributes named __*__
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 05 Apr 1992 14:24:32 +0000 |
| parents | 1e205d0875f6 |
| children | 222f04f55083 |
line wrap: on
line diff
--- a/Objects/classobject.c Sun Apr 05 14:20:22 1992 +0000 +++ b/Objects/classobject.c Sun Apr 05 14:24:32 1992 +0000 @@ -1,5 +1,5 @@ /*********************************************************** -Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The +Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands. All Rights Reserved @@ -106,7 +106,7 @@ int i; for (i = 0; i < n; i++) { v = class_getattr((classobject *) - gettupleitem(op->cl_bases, i), name); + gettupleitem(op->cl_bases, i), name); if (v != NULL) return v; err_clear(); @@ -122,6 +122,13 @@ char *name; 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) return dictremove(op->cl_methods, name); else @@ -226,6 +233,13 @@ char *name; 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) return dictremove(inst->in_attr, name); else
