mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Implemented __methods__ attribute
This commit is contained in:
parent
e6f7d18e6b
commit
e9c430fd3b
1 changed files with 27 additions and 0 deletions
|
@ -130,6 +130,31 @@ typeobject Methodtype = {
|
||||||
0, /*tp_as_mapping*/
|
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.
|
/* Find a method in a module's method table.
|
||||||
Usually called from an object's getattr method. */
|
Usually called from an object's getattr method. */
|
||||||
|
|
||||||
|
@ -139,6 +164,8 @@ findmethod(ml, op, name)
|
||||||
object *op;
|
object *op;
|
||||||
char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
|
if (strcmp(name, "__methods__") == 0)
|
||||||
|
return listmethods(ml);
|
||||||
for (; ml->ml_name != NULL; ml++) {
|
for (; ml->ml_name != NULL; ml++) {
|
||||||
if (strcmp(name, ml->ml_name) == 0)
|
if (strcmp(name, ml->ml_name) == 0)
|
||||||
return newmethodobject(ml->ml_name, ml->ml_meth, op);
|
return newmethodobject(ml->ml_name, ml->ml_meth, op);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue