diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index eae199b33..29bfb791c 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -849,7 +849,7 @@ class ModuleDocumenter(Documenter): if self.options.deprecated: self.add_line(' :deprecated:', sourcename) - def get_object_members(self, want_all: bool) -> Tuple[bool, List[Tuple[str, object]]]: + def get_object_members(self, want_all: bool) -> Tuple[bool, List[Tuple[str, Any]]]: if want_all: if (self.options.ignore_module_all or not hasattr(self.object, '__all__')): diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index 432aa0c85..cdccf710d 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -11,10 +11,10 @@ import importlib import traceback import warnings -from collections import namedtuple -from typing import Any, Callable, Dict, List, Mapping, Tuple +from typing import Any, Callable, Dict, List, Mapping, NamedTuple, Tuple from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias +from sphinx.pycode import ModuleAnalyzer from sphinx.util import logging from sphinx.util.inspect import isclass, isenumclass, safe_getattr @@ -122,11 +122,13 @@ def get_module_members(module: Any) -> List[Tuple[str, Any]]: return sorted(list(members.values())) -Attribute = namedtuple('Attribute', ['name', 'directly_defined', 'value']) +Attribute = NamedTuple('Attribute', [('name', str), + ('directly_defined', bool), + ('value', Any)]) def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable, - analyzer: Any = None) -> Dict[str, Attribute]: + analyzer: ModuleAnalyzer = None) -> Dict[str, Attribute]: """Get members and attributes of target object.""" from sphinx.ext.autodoc import INSTANCEATTR