Skip to content

Commit 4d86047

Browse files
authored
Deprecate Parser.set_application() (#13637)
1 parent e4accf4 commit 4d86047

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Deprecated
1414
including ``builder.app``, ``env.app``, ``events.app``,
1515
and ``SphinxTransform.`app``.
1616
Patch by Adam Turner.
17+
* #13637: Deprecate the :py:meth:`!set_application` method
18+
of :py:class:`~sphinx.parsers.Parser` objects.
19+
Sphinx now directly sets the :py:attr:`!config` and :py:attr:`!env` attributes.
20+
Patch by Adam Turner.
1721

1822
Features added
1923
--------------

sphinx/parsers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from docutils.statemachine import StringList
1111
from docutils.transforms.universal import SmartQuotes
1212

13+
from sphinx.deprecation import _deprecation_warning
1314
from sphinx.util.rst import append_epilog, prepend_prolog
1415

1516
if TYPE_CHECKING:
@@ -44,7 +45,9 @@ def set_application(self, app: Sphinx) -> None:
4445
4546
:param sphinx.application.Sphinx app: Sphinx application object
4647
"""
47-
self._app = app
48+
cls_module = self.__class__.__module__
49+
cls_name = self.__class__.__qualname__
50+
_deprecation_warning(cls_module, f'{cls_name}.set_application', remove=(10, 0))
4851
self.config = app.config
4952
self.env = app.env
5053

sphinx/registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ def create_source_parser(self, app: Sphinx, filename: str) -> Parser:
379379
parser_class = self.get_source_parser(filename)
380380
parser = parser_class()
381381
if isinstance(parser, SphinxParser):
382-
parser.set_application(app)
382+
parser.config = app.config
383+
parser.env = app.env
383384
return parser
384385

385386
def add_translator(

sphinx/testing/restructuredtext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def parse(app: Sphinx, text: str, docname: str = 'index') -> nodes.document:
2222
reader = SphinxStandaloneReader()
2323
reader.setup(app)
2424
parser = RSTParser()
25-
parser.set_application(app)
25+
parser.config = app.config
26+
parser.env = app.env
2627
with sphinx_domains(env):
2728
return publish_doctree(
2829
text,

tests/test_markup/test_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def test_RSTParser_prolog_epilog(RSTStateMachine, app):
1616
document = new_document('dummy.rst')
1717
document.settings = Mock(tab_width=8, language_code='')
1818
parser = RSTParser()
19-
parser.set_application(app)
19+
parser.config = app.config
20+
parser.env = app.env
2021

2122
# normal case
2223
text = 'hello Sphinx world\nSphinx is a document generator'

0 commit comments

Comments
 (0)