diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 34e56eedb..603ad9eb7 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -193,8 +193,10 @@ class ModuleScanner: name, exc, type='autosummary') return False - def scan(self, imported_members: bool, attr_docs: Mapping[str,str] = {}) -> List[str]: + def scan(self, imported_members: bool) -> List[str]: members = [] + analyzer = ModuleAnalyzer.for_module(self.object.__name__) + attr_docs = analyzer.find_attr_docs() for name in members_of(self.object, self.app.config): try: value = safe_getattr(self.object, name) @@ -306,6 +308,8 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any, """Find module attributes with docstrings.""" attrs, public = [], [] try: + analyzer = ModuleAnalyzer.for_module(name) + attr_docs = analyzer.find_attr_docs() for namespace, attr_name in attr_docs: if namespace == '' and attr_name in members: attrs.append(attr_name) @@ -334,10 +338,8 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any, ns.update(context) if doc.objtype == 'module': - analyzer = ModuleAnalyzer.for_module(name) - attr_docs = analyzer.find_attr_docs() scanner = ModuleScanner(app, obj) - ns['members'] = scanner.scan(imported_members, attr_docs) + ns['members'] = scanner.scan(imported_members) ns['functions'], ns['all_functions'] = \ get_members(obj, {'function'}, imported=imported_members) ns['classes'], ns['all_classes'] = \