Skip to content

Commit f1edefe

Browse files
authored
Deprecate the sphinx.io module (#13682)
1 parent f2bf37d commit f1edefe

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Deprecated
2929
* #13679: Non-decodable characters in source files will raise an error in Sphinx 9.
3030
Currently, such bytes are replaced with '?' along with logging a warning.
3131
Patch by Adam Turner.
32+
* #13682: Deprecate :py:mod:`!sphinx.io`.
33+
Sphinx no longer uses the :py:mod:`!sphinx.io` classes,
34+
having replaced them with standard Python I/O.
35+
The entire :py:mod:`!sphinx.io` module will be removed in Sphinx 10.
36+
Patch by Adam Turner.
3237

3338
Features added
3439
--------------

doc/extdev/deprecated.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ The following is a list of deprecated interfaces.
2222
- Removed
2323
- Alternatives
2424

25+
* - ``sphinx.io`` (entire module)
26+
- 8.3
27+
- 10.0
28+
- ``docutils.io`` or standard Python I/O
29+
2530
* - ``sphinx.builders.Builder.app``
2631
- 8.3
2732
- 10.0

sphinx/io.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
from __future__ import annotations
44

5+
import warnings
56
from typing import TYPE_CHECKING
67

78
from docutils.io import FileInput
89
from docutils.readers import standalone
910
from docutils.transforms.references import DanglingReferences
1011
from docutils.writers import UnfilteredWriter
1112

13+
from sphinx.deprecation import RemovedInSphinx10Warning
1214
from sphinx.transforms import SphinxTransformer
1315
from sphinx.util import logging
1416
from sphinx.util.docutils import LoggingReporter
@@ -27,13 +29,23 @@
2729

2830
logger = logging.getLogger(__name__)
2931

32+
warnings.warn('sphinx.io is deprecated', RemovedInSphinx10Warning, stacklevel=2)
33+
3034

3135
class SphinxBaseReader(standalone.Reader): # type: ignore[misc]
3236
"""A base class of readers for Sphinx.
3337
3438
This replaces reporter by Sphinx's on generating document.
3539
"""
3640

41+
def __init__(self, *args: Any, **kwargs: Any) -> None:
42+
super().__init__(*args, **kwargs)
43+
warnings.warn(
44+
'sphinx.io.SphinxBaseReader is deprecated',
45+
RemovedInSphinx10Warning,
46+
stacklevel=2,
47+
)
48+
3749
transforms: list[type[Transform]] = []
3850

3951
def get_transforms(self) -> list[type[Transform]]:
@@ -67,6 +79,14 @@ def new_document(self) -> nodes.document:
6779
class SphinxStandaloneReader(SphinxBaseReader):
6880
"""A basic document reader for Sphinx."""
6981

82+
def __init__(self, *args: Any, **kwargs: Any) -> None:
83+
super().__init__(*args, **kwargs)
84+
warnings.warn(
85+
'sphinx.io.SphinxStandaloneReader is deprecated',
86+
RemovedInSphinx10Warning,
87+
stacklevel=2,
88+
)
89+
7090
def _setup_transforms(self, transforms: list[type[Transform]], /) -> None:
7191
self.transforms = self.transforms + transforms
7292

@@ -92,6 +112,14 @@ def read_source(self, env: BuildEnvironment) -> str:
92112
class SphinxDummyWriter(UnfilteredWriter): # type: ignore[type-arg]
93113
"""Dummy writer module used for generating doctree."""
94114

115+
def __init__(self) -> None:
116+
super().__init__()
117+
warnings.warn(
118+
'sphinx.io.SphinxDummyWriter is deprecated',
119+
RemovedInSphinx10Warning,
120+
stacklevel=2,
121+
)
122+
95123
supported = ('html',) # needed to keep "meta" nodes
96124

97125
def translate(self) -> None:
@@ -100,6 +128,11 @@ def translate(self) -> None:
100128

101129
def SphinxDummySourceClass(source: Any, *args: Any, **kwargs: Any) -> Any:
102130
"""Bypass source object as is to cheat Publisher."""
131+
warnings.warn(
132+
'sphinx.io.SphinxDummySourceClass is deprecated',
133+
RemovedInSphinx10Warning,
134+
stacklevel=2,
135+
)
103136
return source
104137

105138

@@ -109,3 +142,8 @@ class SphinxFileInput(FileInput):
109142
def __init__(self, *args: Any, **kwargs: Any) -> None:
110143
kwargs['error_handler'] = 'sphinx'
111144
super().__init__(*args, **kwargs)
145+
warnings.warn(
146+
'sphinx.io.SphinxFileInput is deprecated',
147+
RemovedInSphinx10Warning,
148+
stacklevel=2,
149+
)

0 commit comments

Comments
 (0)