diff --git a/CHANGES b/CHANGES index 5ad0d36a5..b7376f4fb 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Deprecated * The ``follow_wrapped`` argument of ``sphinx.util.inspect.signature()`` * ``sphinx.ext.autodoc.DataDeclarationDocumenter`` +* ``sphinx.pycode.ModuleAnalyzer.parse()`` * ``sphinx.util.requests.is_ssl_error()`` Features added diff --git a/doc/extdev/deprecated.rst b/doc/extdev/deprecated.rst index 31de41a10..b55a67c32 100644 --- a/doc/extdev/deprecated.rst +++ b/doc/extdev/deprecated.rst @@ -36,6 +36,11 @@ The following is a list of deprecated interfaces. - 5.0 - ``sphinx.ext.autodoc.DataDocumenter`` + * - ``sphinx.pycode.ModuleAnalyzer.parse()`` + - 3.4 + - 5.0 + - ``sphinx.pycode.ModuleAnalyzer.analyze()`` + * - ``sphinx.util.requests.is_ssl_error()`` - 3.4 - 5.0 diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 278e47d88..7e3c6daa4 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1539,7 +1539,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: for cls in self._signature_class.__mro__: try: analyzer = ModuleAnalyzer.for_module(cls.__module__) - analyzer.parse() + analyzer.analyze() qualname = '.'.join([cls.__qualname__, self._signature_method_name]) if qualname in analyzer.overloads: return analyzer.overloads.get(qualname) diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index c1c374bb9..05f45a6d8 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -19,7 +19,7 @@ from os import path from typing import IO, Any, Dict, List, Optional, Tuple from zipfile import ZipFile -from sphinx.deprecation import RemovedInSphinx40Warning +from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning from sphinx.errors import PycodeError from sphinx.pycode.parser import Parser @@ -143,18 +143,24 @@ class ModuleAnalyzer: self._encoding = None self.code = source.read() - # will be filled by parse() + # will be filled by analyze() self.annotations = None # type: Dict[Tuple[str, str], str] self.attr_docs = None # type: Dict[Tuple[str, str], List[str]] self.finals = None # type: List[str] self.overloads = None # type: Dict[str, List[Signature]] self.tagorder = None # type: Dict[str, int] self.tags = None # type: Dict[str, Tuple[str, int, int]] - self._parsed = False + self._analyzed = False def parse(self) -> None: """Parse the source code.""" - if self._parsed: + warnings.warn('ModuleAnalyzer.parse() is deprecated.', + RemovedInSphinx50Warning, stacklevel=2) + self.analyze() + + def analyze(self) -> None: + """Analyze the source code.""" + if self._analyzed: return None try: @@ -179,12 +185,12 @@ class ModuleAnalyzer: def find_attr_docs(self) -> Dict[Tuple[str, str], List[str]]: """Find class and module-level attributes and their documentation.""" - self.parse() + self.analyze() return self.attr_docs def find_tags(self) -> Dict[str, Tuple[str, int, int]]: """Find class, function and method definitions and their location.""" - self.parse() + self.analyze() return self.tags @property