Skip to content

Commit

Permalink
extend __all__ members to template rendering
Browse files Browse the repository at this point in the history
Fixes sphinx-doc#10809

* the option autosummary_ignore_module_all when set to False adds members to module's members entry that will be used for autodoc, but otherwise it ignores it. As such, if a class is available in the __all__, it won't be generated.
* This commit aims at extending the __all__ handling not only to members, but also to corresponding attribute types (function, classes, exceptions, modules)
* In short, the imported_members option is set to True if the object has __all__ member and autosummary is set to have autosummary_ignore_module_all set to False
  • Loading branch information
ClementPinard committed Apr 4, 2023
1 parent 126737c commit 7508de1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sphinx/ext/autosummary/generate.py
Expand Up @@ -321,17 +321,26 @@ def get_modules(obj: Any) -> tuple[list[str], list[str]]:
if doc.objtype == 'module':
scanner = ModuleScanner(app, obj)
ns['members'] = scanner.scan(imported_members)

respect_module_all = not app.config.autosummary_ignore_module_all
imported_members = imported_members or '__all__' in dir(obj) and respect_module_all

ns['functions'], ns['all_functions'] = \
get_members(obj, {'function'}, imported=imported_members)
ns['classes'], ns['all_classes'] = \
get_members(obj, {'class'}, imported=imported_members)
ns['exceptions'], ns['all_exceptions'] = \
get_members(obj, {'exception'}, imported=imported_members)
if respect_module_all:
ns['modules'], ns['all_modules'] = \
get_members(obj, {'module'}, imported=imported_members)
ns['attributes'], ns['all_attributes'] = \
get_module_attrs(ns['members'])
ispackage = hasattr(obj, '__path__')
if ispackage and recursive:
ns['modules'], ns['all_modules'] = get_modules(obj)
modules, all_modules = get_modules(obj)
ns['modules'] = list(set(modules + ns["modules"]))
ns['all_modules'] = list(set(all_modules + ns["all_modules"]))
elif doc.objtype == 'class':
ns['members'] = dir(obj)
ns['inherited_members'] = \
Expand Down

0 comments on commit 7508de1

Please sign in to comment.