Getting a list of an object's methods?

Alexander Schmolck a.schmolck at gmx.net
Mon Jun 23 11:06:14 EDT 2003


mis6 at pitt.edu (Michele Simionato) writes:

> The problem with .mro() is that it is a method of the metaclass
> 'type':
> 
> >>> dir(type)
> ['__base__', '__bases__', '__basicsize__', '__call__', '__class__',
> '__cmp__', '__delattr__', '__dict__', '__dictoffset__', '__doc__',
> '__flags__', '__getattribute__', '__hash__', '__init__',
> '__itemsize__', '__module__', '__mro__', '__name__', '__new__',
> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
> '__subclasses__', '__weakrefoffset__', 'mro']
> 
> IIRC, Tim Peters wrote in this newsgroup some months ago that 'dir'
> was
> designed in such a way to not report metaclass methods. The idea was
> that the typical user doesn't want too much information. Therefore
> 'dir'
> is not meant to be exaustive:
> 
> >>> help(dir)
> Help on built-in function dir:
> 
> dir(...)
>     dir([object]) -> list of strings
>     
>     Return an alphabetized list of names comprising (some of) the
> attributes
>                                                      ^^^^^^^^
>     of the given object, and of attributes reachable from it:
> 
> Nevertheless, one may disagree with this attitude, and I think that if
> enough users protest enough, we may get a more powerful 'dir' in the
> future.

The desirable semantics for `dir` are not relevant here. If 'mro' is a
"member" of `int`, then ``inspect.getmembers(int)`` should return it,
regardless of whatever `dir` does, because that's what its documentation says:

Definition:	inspect.getmembers(object, predicate=None)
Docstring:
    Return all members of an object as (name, value) pairs sorted by name.
    Optionally, only return members that satisfy a given predicate.

Now I have no idea what the hell a "member" is supposed to be (inspect's docu
won't tell you and the only sense in which it occurs in the language ref is
that of set membership (i.e. qualfiying __contains__)), so my guess is that
it's just some ad hoc synonym for attribute (not that I remember stumbling
across a clear definition of attribute anywhere, either).

"Member" better have *some* reasonably well-defined meaning, because unlike
`dir` which is supposed to just give a "convinient" overview of an objects
content in interactive session, AFAICT `inspect.getmembers` is meant to be
used for programming. I somehow prefer my programs to have well-defined
meanings.

So if no-one enlightens me, I shall file a bug report.


'as




More information about the Python-list mailing list