Mercurial > cpython-lru_cache-weakref
diff Objects/methodobject.c @ 395:659b8dbf695c legacy-trunk
Implemented __methods__ attribute
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 20 Oct 1991 20:21:15 +0000 |
| parents | 6ac402023cac |
| children | 1d4b0339b83d |
line wrap: on
line diff
--- a/Objects/methodobject.c Sun Oct 20 20:20:40 1991 +0000 +++ b/Objects/methodobject.c Sun Oct 20 20:21:15 1991 +0000 @@ -130,6 +130,31 @@ 0, /*tp_as_mapping*/ }; +object *listmethods PROTO((struct methodlist *)); /* Forward */ + +static object * +listmethods(ml) + struct methodlist *ml; +{ + int i, n; + object *v; + for (n = 0; ml[n].ml_name != NULL; n++) + ; + v = newlistobject(n); + if (v != NULL) { + for (i = 0; i < n; i++) + setlistitem(v, i, newstringobject(ml[i].ml_name)); + if (err_occurred()) { + DECREF(v); + v = NULL; + } + else { + sortlist(v); + } + } + return v; +} + /* Find a method in a module's method table. Usually called from an object's getattr method. */ @@ -139,6 +164,8 @@ object *op; char *name; { + if (strcmp(name, "__methods__") == 0) + return listmethods(ml); for (; ml->ml_name != NULL; ml++) { if (strcmp(name, ml->ml_name) == 0) return newmethodobject(ml->ml_name, ml->ml_meth, op);
