pv committed 43c99f2

autosummary: fix get_documenter to handle its *parent* parameter correctly

The *parent* parameter is a Python object, and should not be passed on
to Documenter.can_document_member, which expects a Documenter instance.

Comments (0)

Files changed (1)


 # -- autodoc integration -------------------------------------------------------
-    ismemberdescriptor = inspect.ismemberdescriptor
-    isgetsetdescriptor = inspect.isgetsetdescriptor
-except AttributeError:
-    def ismemberdescriptor(obj):
-        return False
-    isgetsetdescriptor = ismemberdescriptor
+class FakeDirective:
+    env = {}
+    genopt = {}
 def get_documenter(obj, parent):
     """Get an autodoc.Documenter class suitable for documenting the given
+    *obj* is the Python object to be documented, and *parent* is an
+    another Python object (e.g. a module or a class) to which *obj*
+    belongs to.
-    from sphinx.ext.autodoc import AutoDirective, DataDocumenter
+    from sphinx.ext.autodoc import AutoDirective, DataDocumenter, \
+         ModuleDocumenter
+    if inspect.ismodule(obj):
+        # ModuleDocumenter.can_document_member always returns False
+        return ModuleDocumenter
+    # Construct a fake documenter for *parent*
+    if parent is not None:
+        parent_doc_cls = get_documenter(parent, None)
+    else:
+        parent_doc_cls = ModuleDocumenter
+    if hasattr(parent, '__name__'):
+        parent_doc = parent_doc_cls(FakeDirective(), parent.__name__)
+    else:
+        parent_doc = parent_doc_cls(FakeDirective(), "")
+    # Get the corrent documenter class for *obj*
     classes = [cls for cls in AutoDirective._registry.values()
-               if cls.can_document_member(obj, '', False, parent)]
+               if cls.can_document_member(obj, '', False, parent_doc)]
     if classes:
         classes.sort(key=lambda cls: cls.priority)
         return classes[-1]
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
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.