Skip to content

Commit 0848c42

Browse files
committed
Recurse through submodules in extension modules
The original method of finding submodules by recursing through the directory structure didn't work with extension modules (aka native "C" extensions) because there is no directory structure to recurse through. This commit adds code to recurse through submodules by inspecting `obj.__all__`, i.e., using the same mechanism that is already used for finding variables, functions, and classes. This is a minimalistic first sketch of a solution. It works on a native extension that I tried it on but it introduces some duplication since there are now two strategies to search for submodules. For a native module, the first strategy (searching the directory structure) will fail but the second (new) strategy (using `obj.__all__`) will work. For regular modules, both strategies will likely work and so the second strategy will just overwrite the results from the first strategy with identical objects. This should technically work but it seems unnecessary. I just don't feel confident enough to remove the first strategy without further guidance.
1 parent aef1917 commit 0848c42

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pdoc/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ def is_from_this_module(obj):
708708
self.doc[name] = Function(name, self, obj)
709709
elif inspect.isclass(obj):
710710
self.doc[name] = Class(name, self, obj)
711+
elif inspect.ismodule(obj):
712+
self.doc[name] = Module(
713+
obj, docfilter=docfilter, supermodule=self,
714+
context=context, skip_errors=skip_errors)
711715
elif name in var_docstrings:
712716
self.doc[name] = Variable(name, self, var_docstrings[name], obj=obj)
713717

0 commit comments

Comments
 (0)