diff options
author | Guido van Rossum <guido@python.org> | 1993-05-19 14:50:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-05-19 14:50:45 (GMT) |
commit | 25831652fd4c03323066d4cafdc0551c396a993e (patch) | |
tree | 69588df0f98b3280402cad3ed95865d06fa21702 /Objects/moduleobject.c | |
parent | 687dd13bfec51849c93db7c538ff41d4c8ecddcb (diff) | |
download | cpython-25831652fd4c03323066d4cafdc0551c396a993e.zip cpython-25831652fd4c03323066d4cafdc0551c396a993e.tar.gz cpython-25831652fd4c03323066d4cafdc0551c396a993e.tar.bz2 |
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.)
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 749d872..8949c7d 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -109,8 +109,12 @@ module_getattr(m, name) 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 @@ module_setattr(m, name, v) 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) |