diff options
author | Guido van Rossum <guido@python.org> | 1991-10-20 20:21:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-10-20 20:21:15 (GMT) |
commit | e9c430fd3be0e28f89333893c166a1b1b109d90e (patch) | |
tree | e5f4755dfe9d3a5ffb093071c1c8b4a229b7bb05 /Objects | |
parent | e6f7d18e6b303f1e2613d0b016bd0dfb6fd337a1 (diff) | |
download | cpython-e9c430fd3be0e28f89333893c166a1b1b109d90e.zip cpython-e9c430fd3be0e28f89333893c166a1b1b109d90e.tar.gz cpython-e9c430fd3be0e28f89333893c166a1b1b109d90e.tar.bz2 |
Implemented __methods__ attribute
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/methodobject.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 46a2f86..d306587 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -130,6 +130,31 @@ typeobject Methodtype = { 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 @@ findmethod(ml, op, name) 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); |