Mercurial > cpython-lru_cache-weakref
diff Objects/classobject.c @ 1290:7971fecbf28e legacy-trunk
* Lots of small changes related to access.
* Added "access *: ...", made access work for class methods.
* Introduced subclass check: make sure that when calling
ClassName.methodname(instance, ...), the instance is an instance of
ClassName or of a subclass thereof (this might break some old code!)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 21 May 1993 19:56:10 +0000 |
| parents | 4d292c7857d4 |
| children | ac3c80abbf43 |
line wrap: on
line diff
--- a/Objects/classobject.c Thu May 20 14:24:46 1993 +0000 +++ b/Objects/classobject.c Fri May 21 19:56:10 1993 +0000 @@ -121,18 +121,24 @@ return v; } v = class_lookup(op, name, &class); - if (v != NULL) { - if (is_accessobject(v)) - v = getaccessvalue(v, getclass()); - else if (is_funcobject(v)) - v = newinstancemethodobject(v, (object *)NULL, + if (v == NULL) { + err_setstr(AttributeError, name); + return NULL; + } + if (is_accessobject(v)) { + v = getaccessvalue(v, getclass()); + if (v == NULL) + return NULL; + } + else + INCREF(v); + if (is_funcobject(v)) { + object *w = newinstancemethodobject(v, (object *)NULL, (object *)class); - else - INCREF(v); - return v; + DECREF(v); + v = w; } - err_setstr(AttributeError, name); - return NULL; + return v; } static int @@ -217,12 +223,6 @@ /* Instance objects */ -typedef struct { - OB_HEAD - classobject *in_class; /* The class object */ - object *in_dict; /* A dictionary */ -} instanceobject; - static object *instance_getattr PROTO((instanceobject *, char *)); static int @@ -241,8 +241,11 @@ pos = 0; while (mappinggetnext(class->cl_dict, &pos, &key, &value)) { + object *v; if (!is_accessobject(value)) continue; + if (hasaccessvalue(value)) + continue; ac = dict2lookup(inst->in_dict, key); if (ac != NULL && is_accessobject(ac)) { err_setval(ConflictError, key); @@ -361,22 +364,27 @@ return (object *)inst->in_class; } v = dictlookup(inst->in_dict, name); - if (v != NULL) { - if (is_accessobject(v)) - v = getaccessvalue(v, getclass()); - else - INCREF(v); - return v; + if (v == NULL) { + v = class_lookup(inst->in_class, name, &class); + if (v == NULL) { + err_setstr(AttributeError, name); + return NULL; + } } - v = class_lookup(inst->in_class, name, &class); - if (v == NULL) - goto error; - if (is_funcobject(v)) - return newinstancemethodobject(v, (object *)inst, - (object *)class); - error: - err_setstr(AttributeError, name); - return NULL; + if (is_accessobject(v)) { + v = getaccessvalue(v, getclass()); + if (v == NULL) + return NULL; + } + else + INCREF(v); + if (is_funcobject(v)) { + object *w = newinstancemethodobject(v, (object *)inst, + (object *)class); + DECREF(v); + v = w; + } + return v; } static int
