Commits

Anonymous committed fb21231

Don't check __module__ for explicitly given members.

Comments (0)

Files changed (2)

   It works like ``add_description_unit`` but the directive will only
   create a target and no output.
 
+* sphinx.ext.autodoc: Don't check ``__module__`` for explicitly given
+  members.
+
 * sphinx.environment: Don't swallow TOC entries when resolving subtrees.
 
 * sphinx.directives: Allow giving a different title to documents

sphinx/ext/autodoc.py

 
 
 def generate_rst(what, name, members, undoc, add_content, document, lineno,
-                 indent='', filename_set=None):
+                 indent='', filename_set=None, check_module=False):
     env = document.settings.env
 
     # find out what to import
             filename_set.add(modfile)
         for part in objpath:
             todoc = getattr(todoc, part)
-        if hasattr(todoc, '__module__'):
-            if todoc.__module__ != mod:
-                return [], result
+        if check_module:
+            # only checking __module__ for members not given explicitly
+            if hasattr(todoc, '__module__'):
+                if todoc.__module__ != mod:
+                    return [], result
         docstring = todoc.__doc__
     except (ImportError, AttributeError):
         warning = document.reporter.warning(
     warnings = []
     # add members, if possible
     _all = members == ['__all__']
+    members_check_module = False
     if _all:
+        if what == 'module':
+            # for implicit module members, check __module__ to avoid documenting
+            # imported objects
+            members_check_module = True
         all_members = sorted(inspect.getmembers(todoc))
     else:
         all_members = [(mname, getattr(todoc, mname)) for mname in members]
                 continue
         full_membername = name + '.' + membername
         subwarn, subres = generate_rst(memberwhat, full_membername, ['__all__'],
-                                       undoc, None, document, lineno, indent)
+                                       undoc, None, document, lineno, indent,
+                                       check_module=members_check_module)
         warnings.extend(subwarn)
         result.extend(subres)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.