summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorWeipeng Hong <hongweichen8888@sina.com>2022-01-23 17:40:38 (GMT)
committerGitHub <noreply@github.com>2022-01-23 17:40:38 (GMT)
commit691506f4e9408a1205166f99640946ad7822e302 (patch)
treed94c7f67a708cfa41bb223a6cdc7ece845dedcf2 /Lib/inspect.py
parent76dc047a0e88d10aad0405228d56e94438cdd91c (diff)
downloadcpython-691506f4e9408a1205166f99640946ad7822e302.zip
cpython-691506f4e9408a1205166f99640946ad7822e302.tar.gz
cpython-691506f4e9408a1205166f99640946ad7822e302.tar.bz2
bpo-46103: Fix inspect.getmembers to only get __bases__ from class (GH-30147)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 879a577..d47f5b7 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -540,23 +540,23 @@ def isabstract(object):
return False
def _getmembers(object, predicate, getter):
+ results = []
+ processed = set()
+ names = dir(object)
if isclass(object):
mro = (object,) + getmro(object)
+ # add any DynamicClassAttributes to the list of names if object is a class;
+ # this may result in duplicate entries if, for example, a virtual
+ # attribute with the same name as a DynamicClassAttribute exists
+ try:
+ for base in object.__bases__:
+ for k, v in base.__dict__.items():
+ if isinstance(v, types.DynamicClassAttribute):
+ names.append(k)
+ except AttributeError:
+ pass
else:
mro = ()
- results = []
- processed = set()
- names = dir(object)
- # :dd any DynamicClassAttributes to the list of names if object is a class;
- # this may result in duplicate entries if, for example, a virtual
- # attribute with the same name as a DynamicClassAttribute exists
- try:
- for base in object.__bases__:
- for k, v in base.__dict__.items():
- if isinstance(v, types.DynamicClassAttribute):
- names.append(k)
- except AttributeError:
- pass
for key in names:
# First try to get the value via getattr. Some descriptors don't
# like calling their __get__ (see bug #1785), so fall back to