Skip to content

Commit 45e1ae6

Browse files
authored
Remove deprecated API (#14095)
1 parent 8256092 commit 45e1ae6

File tree

25 files changed

+99
-656
lines changed

25 files changed

+99
-656
lines changed

doc/extdev/deprecated.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@ The following is a list of deprecated interfaces.
2323
- Alternatives
2424

2525
* - ``sphinx.io`` (entire module)
26-
- 8.3
27-
- 10.0
26+
- 9.0
27+
- 11.0
2828
- ``docutils.io`` or standard Python I/O
2929

3030
* - ``sphinx.builders.Builder.app``
31-
- 8.3
32-
- 10.0
31+
- 9.0
32+
- 11.0
3333
- N/A
3434

3535
* - ``sphinx.environment.BuildEnvironment.app``
36-
- 8.3
37-
- 10.0
36+
- 9.0
37+
- 11.0
3838
- N/A
3939

4040
* - ``sphinx.transforms.Transform.app``
41-
- 8.3
42-
- 10.0
41+
- 9.0
42+
- 11.0
4343
- N/A
4444

4545
* - ``sphinx.transforms.post_transforms.SphinxPostTransform.app``
46-
- 8.3
47-
- 10.0
46+
- 9.0
47+
- 11.0
4848
- N/A
4949

5050
* - ``sphinx.events.EventManager.app``
51-
- 8.3
52-
- 10.0
51+
- 9.0
52+
- 11.0
5353
- N/A
5454

5555
* - ``sphinx.builders.singlehtml.SingleFileHTMLBuilder.fix_refuris``

sphinx/builders/__init__.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import codecs
65
import pickle
76
import re
87
import time
@@ -139,7 +138,7 @@ def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
139138
def app(self) -> Sphinx:
140139
cls_module = self.__class__.__module__
141140
cls_name = self.__class__.__qualname__
142-
_deprecation_warning(cls_module, f'{cls_name}.app', remove=(10, 0))
141+
_deprecation_warning(cls_module, f'{cls_name}.app', remove=(11, 0))
143142
return self._app
144143

145144
@property
@@ -641,15 +640,8 @@ def read_doc(self, docname: str, *, _cache: bool = True) -> None:
641640

642641
filename = env.doc2path(docname)
643642

644-
# set up error_handler for the target document
645-
# xref RemovedInSphinx90Warning
646-
error_handler = _UnicodeDecodeErrorHandler(docname)
647-
codecs.register_error('sphinx', error_handler) # type: ignore[arg-type]
648-
649643
# read the source file
650-
content = filename.read_text(
651-
encoding=env.settings['input_encoding'], errors='sphinx'
652-
)
644+
content = filename.read_text(encoding=env.settings['input_encoding'])
653645

654646
# TODO: move the "source-read" event to here.
655647

@@ -895,30 +887,3 @@ def _write_docname(
895887
builder.phase = BuildPhase.WRITING
896888
builder.write_doc_serialized(docname, doctree)
897889
builder.write_doc(docname, doctree)
898-
899-
900-
class _UnicodeDecodeErrorHandler:
901-
"""Custom error handler for open() that warns and replaces."""
902-
903-
def __init__(self, docname: str, /) -> None:
904-
self.docname = docname
905-
906-
def __call__(self, error: UnicodeDecodeError) -> tuple[str, int]:
907-
obj = error.object
908-
line_start = obj.rfind(b'\n', 0, error.start)
909-
line_end = obj.find(b'\n', error.start)
910-
if line_end == -1:
911-
line_end = len(obj)
912-
line_num = obj.count(b'\n', 0, error.start) + 1
913-
logger.warning(
914-
__(
915-
"undecodable source characters, replacing with '?': '%s>>>%s<<<%s'. "
916-
'This will become an error in Sphinx 9.0.'
917-
# xref RemovedInSphinx90Warning
918-
),
919-
obj[line_start + 1 : error.start].decode(errors='backslashreplace'),
920-
obj[error.start : error.end].decode(errors='backslashreplace'),
921-
obj[error.end : line_end].decode(errors='backslashreplace'),
922-
location=(self.docname, line_num),
923-
)
924-
return '?', error.end

sphinx/builders/html/__init__.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333
from sphinx.builders.html._build_info import BuildInfo
3434
from sphinx.config import ENUM
35-
from sphinx.deprecation import _deprecation_warning
35+
from sphinx.deprecation import _deprecation_warning as _deprecation_warning
3636
from sphinx.domains import Index, IndexEntry
3737
from sphinx.environment.adapters.asset import ImageAdapter
3838
from sphinx.environment.adapters.indexentries import IndexEntries
@@ -258,13 +258,6 @@ def init_highlighter(self) -> None:
258258
else:
259259
self.dark_highlighter = None
260260

261-
@property
262-
def css_files(self) -> list[_CascadingStyleSheet]:
263-
_deprecation_warning(
264-
__name__, f'{self.__class__.__name__}.css_files', remove=(9, 0)
265-
)
266-
return self._css_files
267-
268261
def init_css_files(self) -> None:
269262
self._css_files = []
270263
self.add_css_file('pygments.css', priority=200)
@@ -294,12 +287,6 @@ def add_css_file(self, filename: str, **kwargs: Any) -> None:
294287
if (asset := _CascadingStyleSheet(filename, **kwargs)) not in self._css_files:
295288
self._css_files.append(asset)
296289

297-
@property
298-
def script_files(self) -> list[_JavaScript]:
299-
canonical_name = f'{self.__class__.__name__}.script_files'
300-
_deprecation_warning(__name__, canonical_name, remove=(9, 0))
301-
return self._js_files
302-
303290
def init_js_files(self) -> None:
304291
self._js_files = []
305292
self.add_js_file('documentation_options.js', priority=200)
@@ -1556,26 +1543,3 @@ def setup(app: Sphinx) -> ExtensionMetadata:
15561543
'parallel_read_safe': True,
15571544
'parallel_write_safe': True,
15581545
}
1559-
1560-
1561-
# deprecated name -> (object to return, canonical path or empty string, removal version)
1562-
_DEPRECATED_OBJECTS: dict[str, tuple[Any, str, tuple[int, int]]] = {
1563-
'Stylesheet': (
1564-
_CascadingStyleSheet,
1565-
'sphinx.builders.html._assets._CascadingStyleSheet',
1566-
(9, 0),
1567-
),
1568-
'JavaScript': (_JavaScript, 'sphinx.builders.html._assets._JavaScript', (9, 0)),
1569-
}
1570-
1571-
1572-
def __getattr__(name: str) -> Any:
1573-
if name not in _DEPRECATED_OBJECTS:
1574-
msg = f'module {__name__!r} has no attribute {name!r}'
1575-
raise AttributeError(msg)
1576-
1577-
from sphinx.deprecation import _deprecation_warning
1578-
1579-
deprecated_object, canonical_name, remove = _DEPRECATED_OBJECTS[name]
1580-
_deprecation_warning(__name__, name, canonical_name, remove=remove)
1581-
return deprecated_object

sphinx/builders/html/_assets.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from __future__ import annotations
22

33
import os
4-
import warnings
54
import zlib
65
from functools import cache
76
from typing import TYPE_CHECKING
87

9-
from sphinx.deprecation import RemovedInSphinx90Warning
108
from sphinx.errors import ThemeError
119

1210
if TYPE_CHECKING:
@@ -42,14 +40,6 @@ def __str__(self) -> str:
4240
)
4341

4442
def __eq__(self, other: object) -> bool:
45-
if isinstance(other, str):
46-
warnings.warn(
47-
'The str interface for _CascadingStyleSheet objects is deprecated. '
48-
'Use css.filename instead.',
49-
RemovedInSphinx90Warning,
50-
stacklevel=2,
51-
)
52-
return self.filename == other
5343
if not isinstance(other, _CascadingStyleSheet):
5444
return NotImplemented
5545
return (
@@ -69,24 +59,6 @@ def __delattr__(self, key: str) -> NoReturn:
6959
msg = f'{self.__class__.__name__} is immutable'
7060
raise AttributeError(msg)
7161

72-
def __getattr__(self, key: str) -> str:
73-
warnings.warn(
74-
'The str interface for _CascadingStyleSheet objects is deprecated. '
75-
'Use css.filename instead.',
76-
RemovedInSphinx90Warning,
77-
stacklevel=2,
78-
)
79-
return getattr(os.fspath(self.filename), key)
80-
81-
def __getitem__(self, key: int | slice) -> str:
82-
warnings.warn(
83-
'The str interface for _CascadingStyleSheet objects is deprecated. '
84-
'Use css.filename instead.',
85-
RemovedInSphinx90Warning,
86-
stacklevel=2,
87-
)
88-
return os.fspath(self.filename)[key]
89-
9062

9163
class _JavaScript:
9264
filename: str | os.PathLike[str]
@@ -116,14 +88,6 @@ def __str__(self) -> str:
11688
)
11789

11890
def __eq__(self, other: object) -> bool:
119-
if isinstance(other, str):
120-
warnings.warn(
121-
'The str interface for _JavaScript objects is deprecated. '
122-
'Use js.filename instead.',
123-
RemovedInSphinx90Warning,
124-
stacklevel=2,
125-
)
126-
return self.filename == other
12791
if not isinstance(other, _JavaScript):
12892
return NotImplemented
12993
return (
@@ -143,24 +107,6 @@ def __delattr__(self, key: str) -> NoReturn:
143107
msg = f'{self.__class__.__name__} is immutable'
144108
raise AttributeError(msg)
145109

146-
def __getattr__(self, key: str) -> str:
147-
warnings.warn(
148-
'The str interface for _JavaScript objects is deprecated. '
149-
'Use js.filename instead.',
150-
RemovedInSphinx90Warning,
151-
stacklevel=2,
152-
)
153-
return getattr(os.fspath(self.filename), key)
154-
155-
def __getitem__(self, key: int | slice) -> str:
156-
warnings.warn(
157-
'The str interface for _JavaScript objects is deprecated. '
158-
'Use js.filename instead.',
159-
RemovedInSphinx90Warning,
160-
stacklevel=2,
161-
)
162-
return os.fspath(self.filename)[key]
163-
164110

165111
def _file_checksum(outdir: Path, filename: str | os.PathLike[str]) -> str:
166112
filename = os.fspath(filename)

sphinx/config.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import time
66
import traceback
77
import types
8-
import warnings
98
from contextlib import chdir
109
from os import getenv
1110
from pathlib import Path
1211
from typing import TYPE_CHECKING, Any, Literal, NamedTuple
1312

14-
from sphinx.deprecation import RemovedInSphinx90Warning
1513
from sphinx.errors import ConfigError, ExtensionError
1614
from sphinx.locale import _, __
1715
from sphinx.util import logging
@@ -195,15 +193,6 @@ def __setstate__(
195193
super().__setattr__('valid_types', valid_types)
196194
super().__setattr__('description', description)
197195

198-
def __getitem__(self, item: int | slice) -> Any:
199-
warnings.warn(
200-
f'The {self.__class__.__name__!r} object tuple interface is deprecated, '
201-
"use attribute access instead for 'default', 'rebuild', and 'valid_types'.",
202-
RemovedInSphinx90Warning,
203-
stacklevel=2,
204-
)
205-
return (self.default, self.rebuild, self.valid_types)[item]
206-
207196

208197
class Config:
209198
r"""Configuration file abstraction.

sphinx/deprecation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import warnings
77

88

9-
class RemovedInSphinx90Warning(DeprecationWarning):
9+
class RemovedInSphinx10Warning(DeprecationWarning):
1010
pass
1111

1212

13-
class RemovedInSphinx10Warning(PendingDeprecationWarning):
13+
class RemovedInSphinx11Warning(PendingDeprecationWarning):
1414
pass
1515

1616

17-
RemovedInNextVersionWarning = RemovedInSphinx90Warning
17+
RemovedInNextVersionWarning = RemovedInSphinx10Warning
1818

1919

2020
# By default, all Sphinx deprecation warnings will be emitted.
@@ -50,7 +50,7 @@ def _deprecation_warning(
5050
'deprecated_name': (
5151
object_to_return,
5252
'fully_qualified_replacement_name',
53-
(9, 0),
53+
(10, 0),
5454
),
5555
}
5656
@@ -66,10 +66,10 @@ def __getattr__(name: str) -> Any:
6666
_deprecation_warning(__name__, name, canonical_name, remove=remove)
6767
return deprecated_object
6868
"""
69-
if remove == (9, 0):
70-
warning_class: type[Warning] = RemovedInSphinx90Warning
71-
elif remove == (10, 0):
72-
warning_class = RemovedInSphinx10Warning
69+
if remove == (10, 0):
70+
warning_class: type[Warning] = RemovedInSphinx10Warning
71+
elif remove == (11, 0):
72+
warning_class = RemovedInSphinx11Warning
7373
else:
7474
msg = f'removal version {remove!r} is invalid!'
7575
raise RuntimeError(msg)

sphinx/domains/python/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@
5656

5757
logger = logging.getLogger(__name__)
5858

59-
pairindextypes = {
60-
'module': 'module',
61-
'keyword': 'keyword',
62-
'operator': 'operator',
63-
'object': 'object',
64-
'exception': 'exception',
65-
'statement': 'statement',
66-
'builtin': 'built-in function',
67-
}
68-
6959

7060
class ObjectEntry(NamedTuple):
7161
docname: str

sphinx/environment/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,17 @@ def setup(self, app: Sphinx) -> None:
293293

294294
@property
295295
def app(self) -> Sphinx:
296-
_deprecation_warning(__name__, 'BuildEnvironment.app', remove=(10, 0))
296+
_deprecation_warning(__name__, 'BuildEnvironment.app', remove=(11, 0))
297297
return self._app
298298

299299
@app.setter
300300
def app(self, app: Sphinx) -> None:
301-
_deprecation_warning(__name__, 'BuildEnvironment.app', remove=(10, 0))
301+
_deprecation_warning(__name__, 'BuildEnvironment.app', remove=(11, 0))
302302
self._app = app
303303

304304
@app.deleter
305305
def app(self) -> None:
306-
_deprecation_warning(__name__, 'BuildEnvironment.app', remove=(10, 0))
306+
_deprecation_warning(__name__, 'BuildEnvironment.app', remove=(11, 0))
307307
del self._app
308308

309309
@property

sphinx/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def add(self, name: str) -> None:
8787

8888
@property
8989
def app(self) -> Sphinx:
90-
_deprecation_warning(__name__, 'EventManager.app', remove=(10, 0))
90+
_deprecation_warning(__name__, 'EventManager.app', remove=(11, 0))
9191
return self._app
9292

9393
# ---- Core events -------------------------------------------------------

0 commit comments

Comments
 (0)