Mercurial > cpython-lru_cache-weakref
diff Objects/moduleobject.c @ 1288:9fed5726a36d legacy-trunk
Several changes in one:
(1) dictionaries/mappings now have attributes values() and items() as
well as keys(); at the C level, use the new function mappinggetnext()
to iterate over a dictionary.
(2) "class C(): ..." is now illegal; you must write "class C: ...".
(3) Class objects now know their own name (finally!); and minor
improvements to the way how classes, functions and methods are
represented as strings.
(4) Added an "access" statement and semantics. (This is still
experimental -- as long as you don't use the keyword 'access' nothing
should be changed.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 19 May 1993 14:50:45 +0000 |
| parents | 1cabc2b6c970 |
| children | 4d292c7857d4 |
line wrap: on
line diff
--- a/Objects/moduleobject.c Mon May 17 08:34:16 1993 +0000 +++ b/Objects/moduleobject.c Wed May 19 14:50:45 1993 +0000 @@ -109,8 +109,12 @@ res = dictlookup(m->md_dict, name); if (res == NULL) err_setstr(AttributeError, name); - else - INCREF(res); + else { + if (is_accessobject(res)) + res = getaccessvalue(res, (object *)NULL); + else + INCREF(res); + } return res; } @@ -120,10 +124,17 @@ char *name; object *v; { - if (strcmp(name, "__dict__") == 0 || strcmp(name, "__name__") == 0) { - err_setstr(TypeError, "read-only special attribute"); - return -1; + object *ac; + 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; + } } + ac = dictlookup(m->md_dict, name); + if (ac != NULL && is_accessobject(ac)) + return setaccessvalue(ac, (object *)NULL, v); if (v == NULL) { int rv = dictremove(m->md_dict, name); if (rv < 0)
