summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2013-09-15 01:53:26 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2013-09-15 01:53:26 (GMT)
commit668dede7e91ebe9d0abce48c2c093781ec1888f5 (patch)
treeb12a4f3695bbae85e1d508c4d086bf5858b2ed5d /Lib/inspect.py
parent2131a4a2fc933132c8f2b1f97b3bbf246cccc669 (diff)
downloadcpython-668dede7e91ebe9d0abce48c2c093781ec1888f5.zip
cpython-668dede7e91ebe9d0abce48c2c093781ec1888f5.tar.gz
cpython-668dede7e91ebe9d0abce48c2c093781ec1888f5.tar.bz2
Close #18929: inspect.classify_class_attrs will now search the metaclasses (last) to find where an attr was defined.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 51b7717..371bb35 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -308,9 +308,14 @@ def classify_class_attrs(cls):
data attributes: C.data is just a data object, but
C.__dict__['data'] may be a data descriptor with additional
info, like a __doc__ string.
+
+ If one of the items in dir(cls) is stored in the metaclass it will now
+ be discovered and not have None be listed as the class in which it was
+ defined.
"""
mro = getmro(cls)
+ metamro = getmro(type(cls)) # for attributes stored in the metaclass
names = dir(cls)
result = []
for name in names:
@@ -321,7 +326,7 @@ def classify_class_attrs(cls):
# getattr(). This is the case with some descriptors (bug #1785).
# Thus, we only use getattr() as a last resort.
homecls = None
- for base in (cls,) + mro:
+ for base in (cls,) + mro + metamro:
if name in base.__dict__:
obj = base.__dict__[name]
homecls = base