diff -r 1cfe82916d98 Doc/library/inspect.rst --- a/Doc/library/inspect.rst Mon Sep 09 21:12:21 2013 +0900 +++ b/Doc/library/inspect.rst Mon Sep 09 19:51:58 2013 -0700 @@ -166,22 +166,23 @@ attributes: .. function:: getmembers(object[, predicate]) Return all the members of an object in a list of (name, value) pairs sorted by name. If the optional *predicate* argument is supplied, only members for which the predicate returns a true value are included. .. note:: - :func:`getmembers` does not return metaclass attributes when the argument - is a class (this behavior is inherited from the :func:`dir` function). + :func:`getmembers` will only return metaclass attributes when the + argument is a class and those attributes have been listed in a custom + :meth:`__dir__`. .. function:: getmoduleinfo(path) Returns a :term:`named tuple` ``ModuleInfo(name, suffix, mode, module_type)`` of values that describe how Python will interpret the file identified by *path* if it is a module, or ``None`` if it would not be identified as a module. In that tuple, *name* is the name of the module without the name of any enclosing package, *suffix* is the trailing part of the file name (which may not be a dot-delimited extension), *mode* is the :func:`open` mode that diff -r 1cfe82916d98 Lib/inspect.py --- 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 break else: obj = getattr(cls, name) homecls = getattr(obj, "__objclass__", homecls) # Classify the object. if isinstance(obj, staticmethod):