Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in

Unified Diff: Lib/inspect.py

Issue 18929: inspect.classify_class_attrs ignores metaclass
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/inspect.rst ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/inspect.py Mon Sep 09 21:12:21 2013 +0900
+++ b/Lib/inspect.py Mon Sep 09 19:51:58 2013 -0700
@@ -301,34 +301,39 @@ def classify_class_attrs(cls):
'method' any other flavor of method
'data' not a method
2. The class which defined this attribute (a class).
3. The object as obtained directly from the defining class's
__dict__, not via getattr. This is especially important for
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:
# Get the object associated with the name, and where it was defined.
# Getting an obj from the __dict__ sometimes reveals more than
# using getattr. Static and class methods are dramatic examples.
# Furthermore, some objects may raise an Exception when fetched with
# 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
obj = getattr(cls, name)
homecls = getattr(obj, "__objclass__", homecls)
# Classify the object.
if isinstance(obj, staticmethod):
« no previous file with comments | « Doc/library/inspect.rst ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+