Skip to content

Commit dfb2a91

Browse files
committed
Work around beartype + myst-parser issue
Works around executablebooks/MyST-Parser#1017.
1 parent f9d1cc8 commit dfb2a91

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dynamic = [
3939
dependencies = [
4040
"beartype>=0.18.5",
4141
"docutils>=0.19",
42+
"myst-parser>=4.0.0",
4243
"sphinx>=7.3.5",
4344
]
4445
optional-dependencies.dev = [
@@ -51,7 +52,6 @@ optional-dependencies.dev = [
5152
"interrogate==1.7.0",
5253
"mypy[faster-cache]==1.14.1",
5354
"mypy-strict-kwargs==2024.12.25",
54-
"myst-parser==4.0.0",
5555
"pre-commit==4.0.1",
5656
"pyenchant==3.3.0rc1",
5757
"pylint==3.3.3",

src/sphinx_substitution_extensions/__init__.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from docutils.parsers.rst.roles import code_role
1111
from docutils.parsers.rst.states import Inliner
1212
from docutils.statemachine import StringList
13+
from myst_parser.mocking import MockInliner
1314
from sphinx import addnodes
1415
from sphinx.application import Sphinx
1516
from sphinx.directives.code import CodeBlock
@@ -101,21 +102,31 @@ def __call__( # pylint: disable=dangerous-default-value
101102
rawtext: str,
102103
text: str,
103104
lineno: int,
104-
inliner: Inliner,
105+
inliner: Inliner | MockInliner,
105106
# We allow mutable defaults as the Sphinx implementation requires it.
106107
options: dict[Any, Any] = {}, # noqa: B006
107108
content: list[str] = [], # noqa: B006
108109
) -> tuple[list[Node], list[system_message]]:
109110
"""
110111
Replace placeholders with given variables.
111112
"""
112-
inliner_document = inliner.document
113-
for name, value in inliner_document.substitution_defs.items():
113+
for name, value in inliner.document.substitution_defs.items():
114114
replacement = value.astext()
115115
text = text.replace(f"|{name}|", replacement)
116116
rawtext = text.replace(f"|{name}|", replacement)
117117
rawtext = rawtext.replace(name, replacement)
118118

119+
# ``types-docutils`` says that ``code_role`` requires an ``Inliner``
120+
# for ``inliner``.
121+
#
122+
# We can remove this when
123+
# https://github.com/executablebooks/MyST-Parser/issues/1017
124+
# is resolved by typing ``inliner`` as ``Inliner``.
125+
if isinstance(inliner, MockInliner):
126+
new_inliner = Inliner()
127+
new_inliner.document = inliner.document
128+
inliner = new_inliner
129+
119130
return code_role(
120131
role=typ,
121132
rawtext=rawtext,

0 commit comments

Comments
 (0)