Skip to content

Commit

Permalink
Merge pull request #10301 from tk0miya/refactor_parserapi_doc
Browse files Browse the repository at this point in the history
doc: Update docs for sphinx.parsers.Parser
  • Loading branch information
tk0miya committed Mar 27, 2022
2 parents 7ae8c1e + e530c00 commit f559389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions doc/extdev/parserapi.rst
Expand Up @@ -35,3 +35,4 @@ to configure their settings appropriately.
.. module:: sphinx.parsers

.. autoclass:: Parser
:members:
30 changes: 13 additions & 17 deletions sphinx/parsers.py
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit f559389

Please sign in to comment.