From e530c00b828d2e9343905a32622506e954e06906 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 27 Mar 2022 16:22:44 +0900 Subject: [PATCH] doc: Update docs for sphinx.parsers.Parser --- doc/extdev/parserapi.rst | 1 + sphinx/parsers.py | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/doc/extdev/parserapi.rst b/doc/extdev/parserapi.rst index 1bd03fd0952..c5db2ac9792 100644 --- a/doc/extdev/parserapi.rst +++ b/doc/extdev/parserapi.rst @@ -35,3 +35,4 @@ to configure their settings appropriately. .. module:: sphinx.parsers .. autoclass:: Parser + :members: diff --git a/sphinx/parsers.py b/sphinx/parsers.py index b044f983bd9..6fd74b0cdfc 100644 --- a/sphinx/parsers.py +++ b/sphinx/parsers.py @@ -11,7 +11,9 @@ from docutils.transforms import Transform from docutils.transforms.universal import SmartQuotes +from sphinx.config import Config from sphinx.deprecation import RemovedInSphinx50Warning +from sphinx.environment import BuildEnvironment from sphinx.util.rst import append_epilog, prepend_prolog if TYPE_CHECKING: @@ -24,25 +26,15 @@ class Parser(docutils.parsers.Parser): of ``docutils.parsers.Parser``. Compared with ``docutils.parsers.Parser``, this class improves accessibility to Sphinx APIs. - The subclasses can access the following objects and functions: - - self.app - The application object (:class:`sphinx.application.Sphinx`) - self.config - The config object (:class:`sphinx.config.Config`) - self.env - The environment object (:class:`sphinx.environment.BuildEnvironment`) - self.warn() - Emit a warning. (Same as :meth:`sphinx.application.Sphinx.warn()`) - self.info() - Emit an info message. (Same as :meth:`sphinx.application.Sphinx.info()`) - - .. deprecated:: 1.6 - ``warn()`` and ``info()`` is deprecated. Use :mod:`sphinx.util.logging` instead. - .. deprecated:: 3.0 - parser.app is deprecated. + The subclasses can access sphinx core runtime objects (app, config and env). """ + #: The config object + config: Config + + #: The environment object + env: BuildEnvironment + def set_application(self, app: "Sphinx") -> None: """set_application will be called from Sphinx to set app and other instance variables @@ -54,6 +46,10 @@ def set_application(self, app: "Sphinx") -> None: @property def app(self) -> "Sphinx": + """The application object + + .. deprecated:: 3.0 + """ warnings.warn('parser.app is deprecated.', RemovedInSphinx50Warning, stacklevel=2) return self._app