Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions doc/extdev/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ The following is a list of deprecated interfaces.
- Alternatives

* - ``sphinx.io`` (entire module)
- 8.3
- 10.0
- 9.0
- 11.0
- ``docutils.io`` or standard Python I/O

* - ``sphinx.builders.Builder.app``
- 8.3
- 10.0
- 9.0
- 11.0
- N/A

* - ``sphinx.environment.BuildEnvironment.app``
- 8.3
- 10.0
- 9.0
- 11.0
- N/A

* - ``sphinx.transforms.Transform.app``
- 8.3
- 10.0
- 9.0
- 11.0
- N/A

* - ``sphinx.transforms.post_transforms.SphinxPostTransform.app``
- 8.3
- 10.0
- 9.0
- 11.0
- N/A

* - ``sphinx.events.EventManager.app``
- 8.3
- 10.0
- 9.0
- 11.0
- N/A

* - ``sphinx.builders.singlehtml.SingleFileHTMLBuilder.fix_refuris``
Expand Down
39 changes: 2 additions & 37 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import codecs
import pickle
import re
import time
Expand Down Expand Up @@ -139,7 +138,7 @@ def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
def app(self) -> Sphinx:
cls_module = self.__class__.__module__
cls_name = self.__class__.__qualname__
_deprecation_warning(cls_module, f'{cls_name}.app', remove=(10, 0))
_deprecation_warning(cls_module, f'{cls_name}.app', remove=(11, 0))
return self._app

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

filename = env.doc2path(docname)

# set up error_handler for the target document
# xref RemovedInSphinx90Warning
error_handler = _UnicodeDecodeErrorHandler(docname)
codecs.register_error('sphinx', error_handler) # type: ignore[arg-type]

# read the source file
content = filename.read_text(
encoding=env.settings['input_encoding'], errors='sphinx'
)
content = filename.read_text(encoding=env.settings['input_encoding'])

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

Expand Down Expand Up @@ -895,30 +887,3 @@ def _write_docname(
builder.phase = BuildPhase.WRITING
builder.write_doc_serialized(docname, doctree)
builder.write_doc(docname, doctree)


class _UnicodeDecodeErrorHandler:
"""Custom error handler for open() that warns and replaces."""

def __init__(self, docname: str, /) -> None:
self.docname = docname

def __call__(self, error: UnicodeDecodeError) -> tuple[str, int]:
obj = error.object
line_start = obj.rfind(b'\n', 0, error.start)
line_end = obj.find(b'\n', error.start)
if line_end == -1:
line_end = len(obj)
line_num = obj.count(b'\n', 0, error.start) + 1
logger.warning(
__(
"undecodable source characters, replacing with '?': '%s>>>%s<<<%s'. "
'This will become an error in Sphinx 9.0.'
# xref RemovedInSphinx90Warning
),
obj[line_start + 1 : error.start].decode(errors='backslashreplace'),
obj[error.start : error.end].decode(errors='backslashreplace'),
obj[error.end : line_end].decode(errors='backslashreplace'),
location=(self.docname, line_num),
)
return '?', error.end
38 changes: 1 addition & 37 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)
from sphinx.builders.html._build_info import BuildInfo
from sphinx.config import ENUM
from sphinx.deprecation import _deprecation_warning
from sphinx.deprecation import _deprecation_warning as _deprecation_warning
from sphinx.domains import Index, IndexEntry
from sphinx.environment.adapters.asset import ImageAdapter
from sphinx.environment.adapters.indexentries import IndexEntries
Expand Down Expand Up @@ -258,13 +258,6 @@ def init_highlighter(self) -> None:
else:
self.dark_highlighter = None

@property
def css_files(self) -> list[_CascadingStyleSheet]:
_deprecation_warning(
__name__, f'{self.__class__.__name__}.css_files', remove=(9, 0)
)
return self._css_files

def init_css_files(self) -> None:
self._css_files = []
self.add_css_file('pygments.css', priority=200)
Expand Down Expand Up @@ -294,12 +287,6 @@ def add_css_file(self, filename: str, **kwargs: Any) -> None:
if (asset := _CascadingStyleSheet(filename, **kwargs)) not in self._css_files:
self._css_files.append(asset)

@property
def script_files(self) -> list[_JavaScript]:
canonical_name = f'{self.__class__.__name__}.script_files'
_deprecation_warning(__name__, canonical_name, remove=(9, 0))
return self._js_files

def init_js_files(self) -> None:
self._js_files = []
self.add_js_file('documentation_options.js', priority=200)
Expand Down Expand Up @@ -1556,26 +1543,3 @@ def setup(app: Sphinx) -> ExtensionMetadata:
'parallel_read_safe': True,
'parallel_write_safe': True,
}


# deprecated name -> (object to return, canonical path or empty string, removal version)
_DEPRECATED_OBJECTS: dict[str, tuple[Any, str, tuple[int, int]]] = {
'Stylesheet': (
_CascadingStyleSheet,
'sphinx.builders.html._assets._CascadingStyleSheet',
(9, 0),
),
'JavaScript': (_JavaScript, 'sphinx.builders.html._assets._JavaScript', (9, 0)),
}


def __getattr__(name: str) -> Any:
if name not in _DEPRECATED_OBJECTS:
msg = f'module {__name__!r} has no attribute {name!r}'
raise AttributeError(msg)

from sphinx.deprecation import _deprecation_warning

deprecated_object, canonical_name, remove = _DEPRECATED_OBJECTS[name]
_deprecation_warning(__name__, name, canonical_name, remove=remove)
return deprecated_object
54 changes: 0 additions & 54 deletions sphinx/builders/html/_assets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import annotations

import os
import warnings
import zlib
from functools import cache
from typing import TYPE_CHECKING

from sphinx.deprecation import RemovedInSphinx90Warning
from sphinx.errors import ThemeError

if TYPE_CHECKING:
Expand Down Expand Up @@ -42,14 +40,6 @@ def __str__(self) -> str:
)

def __eq__(self, other: object) -> bool:
if isinstance(other, str):
warnings.warn(
'The str interface for _CascadingStyleSheet objects is deprecated. '
'Use css.filename instead.',
RemovedInSphinx90Warning,
stacklevel=2,
)
return self.filename == other
if not isinstance(other, _CascadingStyleSheet):
return NotImplemented
return (
Expand All @@ -69,24 +59,6 @@ def __delattr__(self, key: str) -> NoReturn:
msg = f'{self.__class__.__name__} is immutable'
raise AttributeError(msg)

def __getattr__(self, key: str) -> str:
warnings.warn(
'The str interface for _CascadingStyleSheet objects is deprecated. '
'Use css.filename instead.',
RemovedInSphinx90Warning,
stacklevel=2,
)
return getattr(os.fspath(self.filename), key)

def __getitem__(self, key: int | slice) -> str:
warnings.warn(
'The str interface for _CascadingStyleSheet objects is deprecated. '
'Use css.filename instead.',
RemovedInSphinx90Warning,
stacklevel=2,
)
return os.fspath(self.filename)[key]


class _JavaScript:
filename: str | os.PathLike[str]
Expand Down Expand Up @@ -116,14 +88,6 @@ def __str__(self) -> str:
)

def __eq__(self, other: object) -> bool:
if isinstance(other, str):
warnings.warn(
'The str interface for _JavaScript objects is deprecated. '
'Use js.filename instead.',
RemovedInSphinx90Warning,
stacklevel=2,
)
return self.filename == other
if not isinstance(other, _JavaScript):
return NotImplemented
return (
Expand All @@ -143,24 +107,6 @@ def __delattr__(self, key: str) -> NoReturn:
msg = f'{self.__class__.__name__} is immutable'
raise AttributeError(msg)

def __getattr__(self, key: str) -> str:
warnings.warn(
'The str interface for _JavaScript objects is deprecated. '
'Use js.filename instead.',
RemovedInSphinx90Warning,
stacklevel=2,
)
return getattr(os.fspath(self.filename), key)

def __getitem__(self, key: int | slice) -> str:
warnings.warn(
'The str interface for _JavaScript objects is deprecated. '
'Use js.filename instead.',
RemovedInSphinx90Warning,
stacklevel=2,
)
return os.fspath(self.filename)[key]


def _file_checksum(outdir: Path, filename: str | os.PathLike[str]) -> str:
filename = os.fspath(filename)
Expand Down
11 changes: 0 additions & 11 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import time
import traceback
import types
import warnings
from contextlib import chdir
from os import getenv
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, NamedTuple

from sphinx.deprecation import RemovedInSphinx90Warning
from sphinx.errors import ConfigError, ExtensionError
from sphinx.locale import _, __
from sphinx.util import logging
Expand Down Expand Up @@ -195,15 +193,6 @@ def __setstate__(
super().__setattr__('valid_types', valid_types)
super().__setattr__('description', description)

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


class Config:
r"""Configuration file abstraction.
Expand Down
16 changes: 8 additions & 8 deletions sphinx/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import warnings


class RemovedInSphinx90Warning(DeprecationWarning):
class RemovedInSphinx10Warning(DeprecationWarning):
pass


class RemovedInSphinx10Warning(PendingDeprecationWarning):
class RemovedInSphinx11Warning(PendingDeprecationWarning):
pass


RemovedInNextVersionWarning = RemovedInSphinx90Warning
RemovedInNextVersionWarning = RemovedInSphinx10Warning


# By default, all Sphinx deprecation warnings will be emitted.
Expand Down Expand Up @@ -50,7 +50,7 @@ def _deprecation_warning(
'deprecated_name': (
object_to_return,
'fully_qualified_replacement_name',
(9, 0),
(10, 0),
),
}
Expand All @@ -66,10 +66,10 @@ def __getattr__(name: str) -> Any:
_deprecation_warning(__name__, name, canonical_name, remove=remove)
return deprecated_object
"""
if remove == (9, 0):
warning_class: type[Warning] = RemovedInSphinx90Warning
elif remove == (10, 0):
warning_class = RemovedInSphinx10Warning
if remove == (10, 0):
warning_class: type[Warning] = RemovedInSphinx10Warning
elif remove == (11, 0):
warning_class = RemovedInSphinx11Warning
else:
msg = f'removal version {remove!r} is invalid!'
raise RuntimeError(msg)
Expand Down
10 changes: 0 additions & 10 deletions sphinx/domains/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@

logger = logging.getLogger(__name__)

pairindextypes = {
'module': 'module',
'keyword': 'keyword',
'operator': 'operator',
'object': 'object',
'exception': 'exception',
'statement': 'statement',
'builtin': 'built-in function',
}


class ObjectEntry(NamedTuple):
docname: str
Expand Down
6 changes: 3 additions & 3 deletions sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,17 @@ def setup(self, app: Sphinx) -> None:

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

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

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

@property
Expand Down
2 changes: 1 addition & 1 deletion sphinx/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def add(self, name: str) -> None:

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

# ---- Core events -------------------------------------------------------
Expand Down
Loading
Loading