diff --git a/doc/ext/autodoc.rst b/doc/ext/autodoc.rst index 7f9a6c61a..c76fb0865 100644 --- a/doc/ext/autodoc.rst +++ b/doc/ext/autodoc.rst @@ -184,12 +184,17 @@ inserting them into the page source under a suitable :rst:dir:`py:module`, .. versionadded:: 0.6 - .. note:: + * In an :rst:dir:`automodule` directive with the ``members`` option set, only + module members whose ``__module__`` attribute is equal to the module name + as given to ``automodule`` will be documented. This is to prevent + documentation of imported classes or functions. + Set ``imported-members`` option if you want to preven this behavior and + document all available members. + Note that attributes from imported modules will not be documented, + because attribute documentation is discovered by parsing the source file + of the current module. - In an :rst:dir:`automodule` directive with the ``members`` option set, only - module members whose ``__module__`` attribute is equal to the module name - as given to ``automodule`` will be documented. This is to prevent - documentation of imported classes or functions. + .. versionadded:: 1.2 .. rst:directive:: autofunction diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 555a31066..432b9ec29 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -364,6 +364,9 @@ class Documenter(object): """Check if *self.object* is really defined in the module given by *self.modname*. """ + if self.options.imported_members: + return True + modname = self.get_attr(self.object, '__module__', None) if modname and modname != self.modname: return False @@ -770,6 +773,7 @@ class ModuleDocumenter(Documenter): 'platform': identity, 'deprecated': bool_option, 'member-order': identity, 'exclude-members': members_set_option, 'private-members': bool_option, 'special-members': members_option, + 'imported-members': bool_option, } @classmethod