summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--doc/extdev/index.rst15
-rw-r--r--sphinx/application.py1
-rw-r--r--sphinx/cmd/build.py3
-rw-r--r--sphinx/config.py3
-rw-r--r--sphinx/ext/imgmath.py6
-rw-r--r--sphinx/search/__init__.py2
-rw-r--r--sphinx/util/console.py6
-rw-r--r--sphinx/util/inspect.py2
-rw-r--r--sphinx/util/pycompat.py18
-rw-r--r--sphinx/util/typing.py3
11 files changed, 40 insertions, 22 deletions
diff --git a/CHANGES b/CHANGES
index 598db0b6a..4c032f04c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -120,10 +120,13 @@ Deprecated
* ``sphinx.util.osutil.EPIPE``
* ``sphinx.util.osutil.walk()``
* ``sphinx.util.PeekableIterator``
+* ``sphinx.util.pycompat.NoneType``
* ``sphinx.util.pycompat.TextIOWrapper``
* ``sphinx.util.pycompat.UnicodeMixin``
* ``sphinx.util.pycompat.htmlescape``
* ``sphinx.util.pycompat.indent``
+* ``sphinx.util.pycompat.sys_encoding``
+* ``sphinx.util.pycompat.terminal_safe()``
* ``sphinx.util.pycompat.u``
* ``sphinx.writers.latex.ExtBabel``
* ``sphinx.writers.latex.LaTeXTranslator._make_visit_admonition()``
diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst
index 95564936c..2bbcd49d3 100644
--- a/doc/extdev/index.rst
+++ b/doc/extdev/index.rst
@@ -420,6 +420,11 @@ The following is a list of deprecated interfaces.
- 4.0
- ``os.walk()``
+ * - ``sphinx.util.pycompat.NoneType``
+ - 2.0
+ - 4.0
+ - ``sphinx.util.typing.NoneType``
+
* - ``sphinx.util.pycompat.TextIOWrapper``
- 2.0
- 4.0
@@ -440,6 +445,16 @@ The following is a list of deprecated interfaces.
- 4.0
- ``textwrap.indent()``
+ * - ``sphinx.util.pycompat.sys_encoding``
+ - 2.0
+ - 4.0
+ - ``sys.getdefaultencoding()``
+
+ * - ``sphinx.util.pycompat.terminal_safe()``
+ - 2.0
+ - 4.0
+ - ``sphinx.util.console.terminal_safe()``
+
* - ``sphinx.util.pycompat.u``
- 2.0
- 4.0
diff --git a/sphinx/application.py b/sphinx/application.py
index cce9926b5..dfeeea6dc 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -37,7 +37,6 @@ from sphinx.registry import SphinxComponentRegistry
from sphinx.util import docutils
from sphinx.util import import_object, progress_message
from sphinx.util import logging
-from sphinx.util import pycompat # noqa: F401
from sphinx.util.build_phase import BuildPhase
from sphinx.util.console import bold # type: ignore
from sphinx.util.docutils import directive_helper
diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py
index 1d4674b9e..6fd954296 100644
--- a/sphinx/cmd/build.py
+++ b/sphinx/cmd/build.py
@@ -23,9 +23,8 @@ from sphinx.application import Sphinx
from sphinx.errors import SphinxError
from sphinx.locale import __
from sphinx.util import Tee, format_exception_cut_frames, save_traceback
-from sphinx.util.console import red, nocolor, color_terminal # type: ignore
+from sphinx.util.console import red, nocolor, color_terminal, terminal_safe # type: ignore
from sphinx.util.docutils import docutils_namespace, patch_docutils
-from sphinx.util.pycompat import terminal_safe
if False:
# For type annotation
diff --git a/sphinx/config.py b/sphinx/config.py
index e4087385f..f844549da 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -22,7 +22,8 @@ from sphinx.locale import _, __
from sphinx.util import logging
from sphinx.util.i18n import format_date
from sphinx.util.osutil import cd
-from sphinx.util.pycompat import execfile_, NoneType
+from sphinx.util.pycompat import execfile_
+from sphinx.util.typing import NoneType
if False:
# For type annotation
diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py
index 00aae13f2..3c6aca78b 100644
--- a/sphinx/ext/imgmath.py
+++ b/sphinx/ext/imgmath.py
@@ -12,6 +12,7 @@ import posixpath
import re
import shutil
import subprocess
+import sys
import tempfile
from hashlib import sha1
from os import path
@@ -26,7 +27,6 @@ from sphinx.util import logging
from sphinx.util.math import get_node_equation_number, wrap_displaymath
from sphinx.util.osutil import ensuredir
from sphinx.util.png import read_png_depth, write_png_depth
-from sphinx.util.pycompat import sys_encoding
if False:
# For type annotation
@@ -46,9 +46,9 @@ class MathExtError(SphinxError):
def __init__(self, msg, stderr=None, stdout=None):
# type: (str, bytes, bytes) -> None
if stderr:
- msg += '\n[stderr]\n' + stderr.decode(sys_encoding, 'replace')
+ msg += '\n[stderr]\n' + stderr.decode(sys.getdefaultencoding(), 'replace')
if stdout:
- msg += '\n[stdout]\n' + stdout.decode(sys_encoding, 'replace')
+ msg += '\n[stdout]\n' + stdout.decode(sys.getdefaultencoding(), 'replace')
super().__init__(msg)
diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py
index c556adc42..dd30b5045 100644
--- a/sphinx/search/__init__.py
+++ b/sphinx/search/__init__.py
@@ -18,8 +18,8 @@ from docutils import nodes
from sphinx import addnodes
from sphinx import package_dir
from sphinx.deprecation import RemovedInSphinx40Warning
-from sphinx.util import jsdump, rpartition
from sphinx.search.jssplitter import splitter_code
+from sphinx.util import jsdump, rpartition
if False:
# For type annotation
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index b419e1284..c207d32ac 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -27,6 +27,12 @@ _ansi_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm')
codes = {} # type: Dict[str, str]
+def terminal_safe(s):
+ # type: (str) -> str
+ """safely encode a string for printing to the terminal."""
+ return s.encode('ascii', 'backslashreplace').decode('ascii')
+
+
def get_terminal_width():
# type: () -> int
"""Borrowed from the py lib."""
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index d4c0f1948..89dd842e3 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -20,7 +20,7 @@ from io import StringIO
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.util import logging
-from sphinx.util.pycompat import NoneType
+from sphinx.util.typing import NoneType
if False:
# For type annotation
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 5f02bd979..fe5f0803e 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -17,6 +17,8 @@ import warnings
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
from sphinx.locale import __
from sphinx.util import logging
+from sphinx.util.console import terminal_safe
+from sphinx.util.typing import NoneType
if False:
# For type annotation
@@ -26,22 +28,9 @@ if False:
logger = logging.getLogger(__name__)
-NoneType = type(None)
-
# ------------------------------------------------------------------------------
# Python 2/3 compatibility
-# sys_encoding: some kind of default system encoding; should be used with
-# a lenient error handler
-sys_encoding = sys.getdefaultencoding()
-
-
-# terminal_safe(): safely encode a string for printing to the terminal
-def terminal_safe(s):
- # type: (str) -> str
- return s.encode('ascii', 'backslashreplace').decode('ascii')
-
-
# convert_with_2to3():
# support for running 2to3 over config files
def convert_with_2to3(filepath):
@@ -99,9 +88,12 @@ def execfile_(filepath, _globals, open=open):
deprecated_alias('sphinx.util.pycompat',
{
+ 'NoneType': NoneType, # type: ignore
'TextIOWrapper': io.TextIOWrapper,
'htmlescape': html.escape,
'indent': textwrap.indent,
+ 'terminal_safe': terminal_safe,
+ 'sys_encoding': sys.getdefaultencoding(),
'u': '',
},
RemovedInSphinx40Warning)
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index 6fb729458..78e8fe61f 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -20,6 +20,9 @@ DirectiveOption = Callable[[str], Any]
# Text like nodes which are initialized with text and rawsource
TextlikeNode = Union[nodes.Text, nodes.TextElement]
+# type of None
+NoneType = type(None)
+
# common role functions
RoleFunction = Callable[[str, str, str, int, Inliner, Dict, List[str]],
Tuple[List[nodes.Node], List[nodes.system_message]]]