From a70626ef154151e274b23ac14db6c60eb526deea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pinard?= Date: Thu, 8 Sep 2022 23:21:33 +0200 Subject: [PATCH] extend __all__ members to template rendering Fixes #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 --- sphinx/ext/autosummary/generate.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 2950d766332..82c9f8fb7b4 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -307,17 +307,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'] = \