Revert part of 13f56cd8dec1 (issue #1785) to avoid breaking getmembers() with unbound methods.

Python 3 isn't affected (unbound methods don't exist).
Thanks to Vincent Pelletier for noticing.
This commit is contained in:
Antoine Pitrou 2012-01-18 17:39:01 +01:00
parent a8f75da8f2
commit e09bc1e8f5
2 changed files with 22 additions and 59 deletions

View file

@ -247,23 +247,12 @@ def isabstract(object):
def getmembers(object, predicate=None):
"""Return all members of an object as (name, value) pairs sorted by name.
Optionally, only return members that satisfy a given predicate."""
if isclass(object):
mro = (object,) + getmro(object)
else:
mro = ()
results = []
for key in dir(object):
# First try to get the value via __dict__. Some descriptors don't
# like calling their __get__ (see bug #1785).
for base in mro:
if key in base.__dict__:
value = base.__dict__[key]
break
else:
try:
value = getattr(object, key)
except AttributeError:
continue
try:
value = getattr(object, key)
except AttributeError:
continue
if not predicate or predicate(value):
results.append((key, value))
results.sort()