]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Implemented __methods__ attribute
authorGuido van Rossum <guido@python.org>
Sun, 20 Oct 1991 20:21:15 +0000 (20:21 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 20 Oct 1991 20:21:15 +0000 (20:21 +0000)
Objects/methodobject.c

index 46a2f86beed62764a1bc8958fb836e7d6efcbd8a..d306587d6e637dcadcd8011ac4750e6c0ea483e0 100644 (file)
@@ -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);