summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-03-07 20:43:25 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-29 15:12:39 +0900
commita86346aca6bf99a8920da366caaad7c47809ecce (patch)
tree7aa786e7817f9f3e6a338d06df2f02534d91a4c5 /sphinx/util
parentaa773cbc88e692df731c78353a1043201bcb9f91 (diff)
downloadsphinx-git-a86346aca6bf99a8920da366caaad7c47809ecce.tar.gz
Remove deprecated features marked as RemovedInSphinx40Warning
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py195
-rw-r--r--sphinx/util/cfamily.py23
-rw-r--r--sphinx/util/compat.py22
-rw-r--r--sphinx/util/docfields.py23
-rw-r--r--sphinx/util/i18n.py81
-rw-r--r--sphinx/util/inspect.py169
-rw-r--r--sphinx/util/jsonimpl.py46
-rw-r--r--sphinx/util/nodes.py8
-rw-r--r--sphinx/util/osutil.py25
-rw-r--r--sphinx/util/pycompat.py54
-rw-r--r--sphinx/util/texescape.py10
11 files changed, 13 insertions, 643 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 8e1d4df84..9a1887759 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -8,7 +8,6 @@
:license: BSD, see LICENSE for details.
"""
-import fnmatch
import functools
import os
import posixpath
@@ -17,9 +16,6 @@ import sys
import tempfile
import traceback
import unicodedata
-import warnings
-from codecs import BOM_UTF8
-from collections import deque
from datetime import datetime
from hashlib import md5
from importlib import import_module
@@ -29,10 +25,7 @@ from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, S
from typing import TYPE_CHECKING
from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
-from sphinx.deprecation import RemovedInSphinx40Warning
-from sphinx.errors import (
- PycodeError, SphinxParallelError, ExtensionError, FiletypeNotFoundError
-)
+from sphinx.errors import SphinxParallelError, ExtensionError, FiletypeNotFoundError
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.console import strip_colors, colorize, bold, term_width_line # type: ignore
@@ -42,7 +35,7 @@ from sphinx.util import smartypants # noqa
# import other utilities; partly for backwards compatibility, so don't
# prune unused ones indiscriminately
from sphinx.util.osutil import ( # noqa
- SEP, os_path, relative_uri, ensuredir, walk, mtimes_of_files, movefile,
+ SEP, os_path, relative_uri, ensuredir, mtimes_of_files, movefile,
copyfile, copytimes, make_filename)
from sphinx.util.nodes import ( # noqa
nested_parse_with_titles, split_explicit_title, explicit_title_re,
@@ -101,23 +94,6 @@ def get_matching_files(dirname: str,
yield filename
-def get_matching_docs(dirname: str, suffixes: List[str],
- exclude_matchers: Tuple[PathMatcher, ...] = ()) -> Iterable[str]:
- """Get all file names (without suffixes) matching a suffix in a directory,
- recursively.
-
- Exclude files and dirs matching a pattern in *exclude_patterns*.
- """
- warnings.warn('get_matching_docs() is now deprecated. Use get_matching_files() instead.',
- RemovedInSphinx40Warning)
- suffixpatterns = ['*' + s for s in suffixes]
- for filename in get_matching_files(dirname, exclude_matchers):
- for suffixpattern in suffixpatterns:
- if fnmatch.fnmatch(filename, suffixpattern):
- yield filename[:-len(suffixpattern) + 1]
- break
-
-
def get_filetype(source_suffix: Dict[str, str], filename: str) -> str:
for suffix, filetype in source_suffix.items():
if filename.endswith(suffix):
@@ -243,53 +219,6 @@ def save_traceback(app: "Sphinx") -> str:
return path
-def get_module_source(modname: str) -> Tuple[str, str]:
- """Try to find the source code for a module.
-
- Can return ('file', 'filename') in which case the source is in the given
- file, or ('string', 'source') which which case the source is the string.
- """
- warnings.warn('get_module_source() is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
- try:
- mod = import_module(modname)
- except Exception as err:
- raise PycodeError('error importing %r' % modname, err)
- filename = getattr(mod, '__file__', None)
- loader = getattr(mod, '__loader__', None)
- if loader and getattr(loader, 'get_filename', None):
- try:
- filename = loader.get_filename(modname)
- except Exception as err:
- raise PycodeError('error getting filename for %r' % filename, err)
- if filename is None and loader:
- try:
- filename = loader.get_source(modname)
- if filename:
- return 'string', filename
- except Exception as err:
- raise PycodeError('error getting source for %r' % modname, err)
- if filename is None:
- raise PycodeError('no source found for module %r' % modname)
- filename = path.normpath(path.abspath(filename))
- lfilename = filename.lower()
- if lfilename.endswith('.pyo') or lfilename.endswith('.pyc'):
- filename = filename[:-1]
- if not path.isfile(filename) and path.isfile(filename + 'w'):
- filename += 'w'
- elif not (lfilename.endswith('.py') or lfilename.endswith('.pyw')):
- raise PycodeError('source is not a .py file: %r' % filename)
- elif ('.egg' + os.path.sep) in filename:
- pat = '(?<=\\.egg)' + re.escape(os.path.sep)
- eggpath, _ = re.split(pat, filename, 1)
- if path.isfile(eggpath):
- return 'file', filename
-
- if not path.isfile(filename):
- raise PycodeError('source file is not present: %r' % filename)
- return 'file', filename
-
-
def get_full_modname(modname: str, attribute: str) -> str:
if modname is None:
# Prevents a TypeError: if the last getattr() call will return None
@@ -311,58 +240,6 @@ def get_full_modname(modname: str, attribute: str) -> str:
_coding_re = re.compile(r'coding[:=]\s*([-\w.]+)')
-def detect_encoding(readline: Callable[[], bytes]) -> str:
- """Like tokenize.detect_encoding() from Py3k, but a bit simplified."""
- warnings.warn('sphinx.util.detect_encoding() is deprecated',
- RemovedInSphinx40Warning)
-
- def read_or_stop() -> bytes:
- try:
- return readline()
- except StopIteration:
- return None
-
- def get_normal_name(orig_enc: str) -> str:
- """Imitates get_normal_name in tokenizer.c."""
- # Only care about the first 12 characters.
- enc = orig_enc[:12].lower().replace('_', '-')
- if enc == 'utf-8' or enc.startswith('utf-8-'):
- return 'utf-8'
- if enc in ('latin-1', 'iso-8859-1', 'iso-latin-1') or \
- enc.startswith(('latin-1-', 'iso-8859-1-', 'iso-latin-1-')):
- return 'iso-8859-1'
- return orig_enc
-
- def find_cookie(line: bytes) -> str:
- try:
- line_string = line.decode('ascii')
- except UnicodeDecodeError:
- return None
-
- matches = _coding_re.findall(line_string)
- if not matches:
- return None
- return get_normal_name(matches[0])
-
- default = sys.getdefaultencoding()
- first = read_or_stop()
- if first and first.startswith(BOM_UTF8):
- first = first[3:]
- default = 'utf-8-sig'
- if not first:
- return default
- encoding = find_cookie(first)
- if encoding:
- return encoding
- second = read_or_stop()
- if not second:
- return default
- encoding = find_cookie(second)
- if encoding:
- return encoding
- return default
-
-
class UnicodeDecodeErrorHandler:
"""Custom error handler for open() that warns and replaces."""
@@ -431,39 +308,6 @@ def parselinenos(spec: str, total: int) -> List[int]:
return items
-def force_decode(string: str, encoding: str) -> str:
- """Forcibly get a unicode string out of a bytestring."""
- warnings.warn('force_decode() is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
- if isinstance(string, bytes):
- try:
- if encoding:
- string = string.decode(encoding)
- else:
- # try decoding with utf-8, should only work for real UTF-8
- string = string.decode()
- except UnicodeError:
- # last resort -- can't fail
- string = string.decode('latin1')
- return string
-
-
-class attrdict(dict):
- def __init__(self, *args: Any, **kwargs: Any) -> None:
- super().__init__(*args, **kwargs)
- warnings.warn('The attrdict class is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
-
- def __getattr__(self, key: str) -> str:
- return self[key]
-
- def __setattr__(self, key: str, val: str) -> None:
- self[key] = val
-
- def __delattr__(self, key: str) -> None:
- del self[key]
-
-
def rpartition(s: str, t: str) -> Tuple[str, str]:
"""Similar to str.rpartition from 2.5, but doesn't return the separator."""
i = s.rfind(t)
@@ -512,41 +356,6 @@ def format_exception_cut_frames(x: int = 1) -> str:
return ''.join(res)
-class PeekableIterator:
- """
- An iterator which wraps any iterable and makes it possible to peek to see
- what's the next item.
- """
- def __init__(self, iterable: Iterable) -> None:
- self.remaining = deque() # type: deque
- self._iterator = iter(iterable)
- warnings.warn('PeekableIterator is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
-
- def __iter__(self) -> "PeekableIterator":
- return self
-
- def __next__(self) -> Any:
- """Return the next item from the iterator."""
- if self.remaining:
- return self.remaining.popleft()
- return next(self._iterator)
-
- next = __next__ # Python 2 compatibility
-
- def push(self, item: Any) -> None:
- """Push the `item` on the internal stack, it will be returned on the
- next :meth:`next` call.
- """
- self.remaining.append(item)
-
- def peek(self) -> Any:
- """Return the next item without changing the state of the iterator."""
- item = next(self)
- self.push(item)
- return item
-
-
def import_object(objname: str, source: str = None) -> Any:
"""Import python object by qualname."""
try:
diff --git a/sphinx/util/cfamily.py b/sphinx/util/cfamily.py
index 790a492a5..4cef9a563 100644
--- a/sphinx/util/cfamily.py
+++ b/sphinx/util/cfamily.py
@@ -9,7 +9,6 @@
"""
import re
-import warnings
from copy import deepcopy
from typing import (
Any, Callable, List, Match, Pattern, Tuple, Union
@@ -19,7 +18,6 @@ from docutils import nodes
from docutils.nodes import TextElement
from sphinx.config import Config
-from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.util import logging
logger = logging.getLogger(__name__)
@@ -75,12 +73,7 @@ def verify_description_mode(mode: str) -> None:
class NoOldIdError(Exception):
# Used to avoid implementing unneeded id generation for old id schemes.
- @property
- def description(self) -> str:
- warnings.warn('%s.description is deprecated. '
- 'Coerce the instance to a string instead.' % self.__class__.__name__,
- RemovedInSphinx40Warning, stacklevel=2)
- return str(self)
+ pass
class ASTBaseBase:
@@ -201,21 +194,11 @@ class ASTParenAttribute(ASTAttribute):
class UnsupportedMultiCharacterCharLiteral(Exception):
- @property
- def decoded(self) -> str:
- warnings.warn('%s.decoded is deprecated. '
- 'Coerce the instance to a string instead.' % self.__class__.__name__,
- RemovedInSphinx40Warning, stacklevel=2)
- return str(self)
+ pass
class DefinitionError(Exception):
- @property
- def description(self) -> str:
- warnings.warn('%s.description is deprecated. '
- 'Coerce the instance to a string instead.' % self.__class__.__name__,
- RemovedInSphinx40Warning, stacklevel=2)
- return str(self)
+ pass
class BaseParser:
diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py
index 502edb525..2c38f668b 100644
--- a/sphinx/util/compat.py
+++ b/sphinx/util/compat.py
@@ -9,16 +9,9 @@
"""
import sys
-import warnings
from typing import Any, Dict
from typing import TYPE_CHECKING
-from docutils.utils import get_source_line
-
-from sphinx import addnodes
-from sphinx.deprecation import RemovedInSphinx40Warning
-from sphinx.transforms import SphinxTransform
-
if TYPE_CHECKING:
from sphinx.application import Sphinx
@@ -36,22 +29,7 @@ def register_application_for_autosummary(app: "Sphinx") -> None:
autosummary._app = app
-class IndexEntriesMigrator(SphinxTransform):
- """Migrating indexentries from old style (4columns) to new style (5columns)."""
- default_priority = 700
-
- def apply(self, **kwargs: Any) -> None:
- for node in self.document.traverse(addnodes.index):
- for i, entries in enumerate(node['entries']):
- if len(entries) == 4:
- source, line = get_source_line(node)
- warnings.warn('An old styled index node found: %r at (%s:%s)' %
- (node, source, line), RemovedInSphinx40Warning)
- node['entries'][i] = entries + (None,)
-
-
def setup(app: "Sphinx") -> Dict[str, Any]:
- app.add_transform(IndexEntriesMigrator)
app.connect('builder-inited', register_application_for_autosummary)
return {
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index 561271c4f..cb11a799d 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -9,7 +9,6 @@
:license: BSD, see LICENSE for details.
"""
-import warnings
from typing import Any, Dict, List, Tuple, Type, Union
from typing import TYPE_CHECKING, cast
@@ -17,7 +16,6 @@ from docutils import nodes
from docutils.nodes import Node
from sphinx import addnodes
-from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.util.typing import TextlikeNode
if TYPE_CHECKING:
@@ -217,26 +215,7 @@ class DocFieldTransformer:
def __init__(self, directive: "ObjectDescription") -> None:
self.directive = directive
- try:
- self.typemap = directive.get_field_type_map()
- except Exception:
- # for 3rd party extensions directly calls this transformer.
- warnings.warn('DocFieldTransformer expects given directive object is a subclass '
- 'of ObjectDescription.', RemovedInSphinx40Warning)
- self.typemap = self.preprocess_fieldtypes(directive.__class__.doc_field_types)
-
- def preprocess_fieldtypes(self, types: List[Field]) -> Dict[str, Tuple[Field, bool]]:
- warnings.warn('DocFieldTransformer.preprocess_fieldtypes() is deprecated.',
- RemovedInSphinx40Warning)
- typemap = {}
- for fieldtype in types:
- for name in fieldtype.names:
- typemap[name] = fieldtype, False
- if fieldtype.is_typed:
- typed_field = cast(TypedField, fieldtype)
- for name in typed_field.typenames:
- typemap[name] = typed_field, True
- return typemap
+ self.typemap = directive.get_field_type_map()
def transform_all(self, node: addnodes.desc_content) -> None:
"""Transform all field list children of a node."""
diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py
index f58b0faaf..398accf1a 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -7,24 +7,21 @@
:copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-import gettext
+
import os
import re
-import warnings
from datetime import datetime, timezone
from os import path
-from typing import Callable, Generator, List, NamedTuple, Set, Tuple
+from typing import Callable, Generator, List, NamedTuple, Tuple
from typing import TYPE_CHECKING
import babel.dates
from babel.messages.mofile import write_mo
from babel.messages.pofile import read_po
-from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.errors import SphinxError
from sphinx.locale import __
from sphinx.util import logging
-from sphinx.util.matching import Matcher
from sphinx.util.osutil import SEP, canon_path, relpath
if TYPE_CHECKING:
@@ -120,17 +117,6 @@ class CatalogRepository:
yield CatalogInfo(basedir, domain, self.encoding)
-def find_catalog(docname: str, compaction: bool) -> str:
- warnings.warn('find_catalog() is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
- if compaction:
- ret = docname.split(SEP, 1)[0]
- else:
- ret = docname
-
- return ret
-
-
def docname_to_domain(docname: str, compation: bool) -> str:
"""Convert docname to domain for catalogs."""
if compation:
@@ -139,69 +125,6 @@ def docname_to_domain(docname: str, compation: bool) -> str:
return docname
-def find_catalog_files(docname: str, srcdir: str, locale_dirs: List[str],
- lang: str, compaction: bool) -> List[str]:
- warnings.warn('find_catalog_files() is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
- if not(lang and locale_dirs):
- return []
-
- domain = find_catalog(docname, compaction)
- files = [gettext.find(domain, path.join(srcdir, dir_), [lang])
- for dir_ in locale_dirs]
- files = [relpath(f, srcdir) for f in files if f]
- return files
-
-
-def find_catalog_source_files(locale_dirs: List[str], locale: str, domains: List[str] = None,
- charset: str = 'utf-8', force_all: bool = False,
- excluded: Matcher = Matcher([])) -> Set[CatalogInfo]:
- """
- :param list locale_dirs:
- list of path as `['locale_dir1', 'locale_dir2', ...]` to find
- translation catalogs. Each path contains a structure such as
- `<locale>/LC_MESSAGES/domain.po`.
- :param str locale: a language as `'en'`
- :param list domains: list of domain names to get. If empty list or None
- is specified, get all domain names. default is None.
- :param boolean force_all:
- Set True if you want to get all catalogs rather than updated catalogs.
- default is False.
- :return: [CatalogInfo(), ...]
- """
- warnings.warn('find_catalog_source_files() is deprecated.',
- RemovedInSphinx40Warning, stacklevel=2)
-
- catalogs = set() # type: Set[CatalogInfo]
-
- if not locale:
- return catalogs # locale is not specified
-
- for locale_dir in locale_dirs:
- if not locale_dir:
- continue # skip system locale directory
-
- base_dir = path.join(locale_dir, locale, 'LC_MESSAGES')
-
- if not path.exists(base_dir):
- continue # locale path is not found
-
- for dirpath, dirnames, filenames in os.walk(base_dir, followlinks=True):
- filenames = [f for f in filenames if f.endswith('.po')]
- for filename in filenames:
- if excluded(path.join(relpath(dirpath, base_dir), filename)):
- continue
- base = path.splitext(filename)[0]
- domain = relpath(path.join(dirpath, base), base_dir).replace(path.sep, SEP)
- if domains and domain not in domains:
- continue
- cat = CatalogInfo(base_dir, domain, charset)
- if force_all or cat.is_outdated():
- catalogs.add(cat)
-
- return catalogs
-
-
# date_format mappings: ustrftime() to bable.dates.format_datetime()
date_format_mappings = {
'%a': 'EEE', # Weekday as locale’s abbreviated name.
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 5a73774c7..17b19ae76 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -20,10 +20,10 @@ from inspect import ( # NOQA
Parameter, isclass, ismethod, ismethoddescriptor
)
from io import StringIO
-from typing import Any, Callable, Mapping, List, Optional, Tuple
+from typing import Any, Callable
from typing import cast
-from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning
+from sphinx.deprecation import RemovedInSphinx50Warning
from sphinx.pycode.ast import ast # for py36-37
from sphinx.pycode.ast import unparse as ast_unparse
from sphinx.util import logging
@@ -323,23 +323,6 @@ def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
raise AttributeError(name)
-def safe_getmembers(object: Any, predicate: Callable[[str], bool] = None,
- attr_getter: Callable = safe_getattr) -> List[Tuple[str, Any]]:
- """A version of inspect.getmembers() that uses safe_getattr()."""
- warnings.warn('safe_getmembers() is deprecated', RemovedInSphinx40Warning)
-
- results = [] # type: List[Tuple[str, Any]]
- for key in dir(object):
- try:
- value = attr_getter(object, key, None)
- except AttributeError:
- continue
- if not predicate or predicate(value):
- results.append((key, value))
- results.sort()
- return results
-
-
def object_description(object: Any) -> str:
"""A repr() implementation that returns text safe to use in reST context."""
if isinstance(object, dict):
@@ -542,154 +525,6 @@ def signature_from_str(signature: str) -> inspect.Signature:
return inspect.Signature(params, return_annotation=return_annotation)
-class Signature:
- """The Signature object represents the call signature of a callable object and
- its return annotation.
- """
-
- empty = inspect.Signature.empty
-
- def __init__(self, subject: Callable, bound_method: bool = False,
- has_retval: bool = True) -> None:
- warnings.warn('sphinx.util.inspect.Signature() is deprecated',
- RemovedInSphinx40Warning)
-
- # check subject is not a built-in class (ex. int, str)
- if (isinstance(subject, type) and
- is_builtin_class_method(subject, "__new__") and
- is_builtin_class_method(subject, "__init__")):
- raise TypeError("can't compute signature for built-in type {}".format(subject))
-
- self.subject = subject
- self.has_retval = has_retval
- self.partialmethod_with_noargs = False
-
- try:
- self.signature = inspect.signature(subject) # type: Optional[inspect.Signature]
- except IndexError:
- # Until python 3.6.4, cpython has been crashed on inspection for
- # partialmethods not having any arguments.
- # https://bugs.python.org/issue33009
- if hasattr(subject, '_partialmethod'):
- self.signature = None
- self.partialmethod_with_noargs = True
- else:
- raise
-
- try:
- self.annotations = typing.get_type_hints(subject)
- except Exception:
- # get_type_hints() does not support some kind of objects like partial,
- # ForwardRef and so on. For them, it raises an exception. In that case,
- # we try to build annotations from argspec.
- self.annotations = {}
-
- if bound_method:
- # client gives a hint that the subject is a bound method
-
- if inspect.ismethod(subject):
- # inspect.signature already considers the subject is bound method.
- # So it is not need to skip first argument.
- self.skip_first_argument = False
- else:
- self.skip_first_argument = True
- else:
- # inspect.signature recognizes type of method properly without any hints
- self.skip_first_argument = False
-
- @property
- def parameters(self) -> Mapping:
- if self.partialmethod_with_noargs:
- return {}
- else:
- return self.signature.parameters
-
- @property
- def return_annotation(self) -> Any:
- if self.signature:
- if self.has_retval:
- return self.signature.return_annotation
- else:
- return Parameter.empty
- else:
- return None
-
- def format_args(self, show_annotation: bool = True) -> str:
- def get_annotation(param: Parameter) -> Any:
- if isinstance(param.annotation, str) and param.name in self.annotations:
- return self.annotations[param.name]
- else:
- return param.annotation
-
- args = []
- last_kind = None
- for i, param in enumerate(self.parameters.values()):
- # skip first argument if subject is bound method
- if self.skip_first_argument and i == 0:
- continue
-
- arg = StringIO()
-
- # insert '*' between POSITIONAL args and KEYWORD_ONLY args::
- # func(a, b, *, c, d):
- if param.kind == param.KEYWORD_ONLY and last_kind in (param.POSITIONAL_OR_KEYWORD,
- param.POSITIONAL_ONLY,
- None):
- args.append('*')
-
- if param.kind in (param.POSITIONAL_ONLY,
- param.POSITIONAL_OR_KEYWORD,
- param.KEYWORD_ONLY):
- arg.write(param.name)
- if show_annotation and param.annotation is not param.empty:
- arg.write(': ')
- arg.write(stringify_annotation(get_annotation(param)))
- if param.default is not param.empty:
- if param.annotation is param.empty or show_annotation is False:
- arg.write('=')
- arg.write(object_description(param.default))
- else:
- arg.write(' = ')
- arg.write(object_description(param.default))
- elif param.kind == param.VAR_POSITIONAL:
- arg.write('*')
- arg.write(param.name)
- if show_annotation and param.annotation is not param.empty:
- arg.write(': ')
- arg.write(stringify_annotation(get_annotation(param)))
- elif param.kind == param.VAR_KEYWORD:
- arg.write('**')
- arg.write(param.name)
- if show_annotation and param.annotation is not param.empty:
- arg.write(': ')
- arg.write(stringify_annotation(get_annotation(param)))
-
- args.append(arg.getvalue())
- last_kind = param.kind
-
- if self.return_annotation is Parameter.empty or show_annotation is False:
- return '(%s)' % ', '.join(args)
- else:
- if 'return' in self.annotations:
- annotation = stringify_annotation(self.annotations['return'])
- else:
- annotation = stringify_annotation(self.return_annotation)
-
- return '(%s) -> %s' % (', '.join(args), annotation)
-
- def format_annotation(self, annotation: Any) -> str:
- """Return formatted representation of a type annotation."""
- return stringify_annotation(annotation)
-
- def format_annotation_new(self, annotation: Any) -> str:
- """format_annotation() for py37+"""
- return stringify_annotation(annotation)
-
- def format_annotation_old(self, annotation: Any) -> str:
- """format_annotation() for py36 or below"""
- return stringify_annotation(annotation)
-
-
def getdoc(obj: Any, attrgetter: Callable = safe_getattr,
allow_inherited: bool = False) -> str:
"""Get the docstring for the object.
diff --git a/sphinx/util/jsonimpl.py b/sphinx/util/jsonimpl.py
deleted file mode 100644
index 35501f03a..000000000
--- a/sphinx/util/jsonimpl.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""
- sphinx.util.jsonimpl
- ~~~~~~~~~~~~~~~~~~~~
-
- JSON serializer implementation wrapper.
-
- :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
- :license: BSD, see LICENSE for details.
-"""
-
-import json
-import warnings
-from collections import UserString
-from typing import Any, IO
-
-from sphinx.deprecation import RemovedInSphinx40Warning
-
-
-warnings.warn('sphinx.util.jsonimpl is deprecated',
- RemovedInSphinx40Warning, stacklevel=2)
-
-
-class SphinxJSONEncoder(json.JSONEncoder):
- """JSONEncoder subclass that forces translation proxies."""
- def default(self, obj: Any) -> str:
- if isinstance(obj, UserString):
- return str(obj)
- return super().default(obj)
-
-
-def dump(obj: Any, fp: IO, *args: Any, **kwargs: Any) -> None:
- kwargs['cls'] = SphinxJSONEncoder
- json.dump(obj, fp, *args, **kwargs)
-
-
-def dumps(obj: Any, *args: Any, **kwargs: Any) -> str:
- kwargs['cls'] = SphinxJSONEncoder
- return json.dumps(obj, *args, **kwargs)
-
-
-def load(*args: Any, **kwargs: Any) -> Any:
- return json.load(*args, **kwargs)
-
-
-def loads(*args: Any, **kwargs: Any) -> Any:
- return json.loads(*args, **kwargs)
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index 35594c087..1d92ce836 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -10,7 +10,6 @@
import re
import unicodedata
-import warnings
from typing import Any, Callable, Iterable, List, Set, Tuple, Type
from typing import TYPE_CHECKING, cast
@@ -21,7 +20,6 @@ from docutils.parsers.rst.states import Inliner
from docutils.statemachine import StringList
from sphinx import addnodes
-from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.locale import __
from sphinx.util import logging
@@ -276,12 +274,6 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]:
yield node, msg
-def find_source_node(node: Element) -> str:
- warnings.warn('find_source_node() is deprecated.',
- RemovedInSphinx40Warning)
- return get_node_source(node)
-
-
def get_node_source(node: Element) -> str:
for pnode in traverse_parent(node):
if pnode.source:
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 6f4322535..e3c4ebedb 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -9,18 +9,14 @@
"""
import contextlib
-import errno
import filecmp
import os
import re
import shutil
import sys
-import warnings
from io import StringIO
from os import path
-from typing import Any, Generator, Iterator, List, Optional, Tuple, Type
-
-from sphinx.deprecation import RemovedInSphinx40Warning
+from typing import Any, Generator, Iterator, List, Optional, Type
try:
# for ALT Linux (#6712)
@@ -28,11 +24,6 @@ try:
except ImportError:
Path = None # type: ignore
-# Errnos that we need.
-EEXIST = getattr(errno, 'EEXIST', 0) # RemovedInSphinx40Warning
-ENOENT = getattr(errno, 'ENOENT', 0) # RemovedInSphinx40Warning
-EPIPE = getattr(errno, 'EPIPE', 0) # RemovedInSphinx40Warning
-EINVAL = getattr(errno, 'EINVAL', 0) # RemovedInSphinx40Warning
# SEP separates path elements in the canonical file names
#
@@ -79,13 +70,6 @@ def ensuredir(path: str) -> None:
os.makedirs(path, exist_ok=True)
-def walk(top: str, topdown: bool = True, followlinks: bool = False) -> Iterator[Tuple[str, List[str], List[str]]]: # NOQA
- warnings.warn('sphinx.util.osutil.walk() is deprecated for removal. '
- 'Please use os.walk() instead.',
- RemovedInSphinx40Warning)
- return os.walk(top, topdown=topdown, followlinks=followlinks)
-
-
def mtimes_of_files(dirnames: List[str], suffix: str) -> Iterator[float]:
for dirname in dirnames:
for root, dirs, files in os.walk(dirname):
@@ -171,13 +155,6 @@ def abspath(pathdir: str) -> str:
return pathdir
-def getcwd() -> str:
- warnings.warn('sphinx.util.osutil.getcwd() is deprecated. '
- 'Please use os.getcwd() instead.',
- RemovedInSphinx40Warning)
- return os.getcwd()
-
-
@contextlib.contextmanager
def cd(target_dir: str) -> Generator[None, None, None]:
cwd = os.getcwd()
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 88e9ac8d5..bcd90a718 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -8,23 +8,10 @@
:license: BSD, see LICENSE for details.
"""
-import html
-import io
-import sys
-import textwrap
import warnings
from typing import Any, Callable
-from sphinx.deprecation import (
- RemovedInSphinx40Warning, RemovedInSphinx60Warning, deprecated_alias
-)
-from sphinx.locale import __
-from sphinx.util import logging
-from sphinx.util.console import terminal_safe
-from sphinx.util.typing import NoneType
-
-
-logger = logging.getLogger(__name__)
+from sphinx.deprecation import RemovedInSphinx60Warning
# ------------------------------------------------------------------------------
@@ -51,18 +38,6 @@ def convert_with_2to3(filepath: str) -> str:
return str(tree)
-class UnicodeMixin:
- """Mixin class to handle defining the proper __str__/__unicode__
- methods in Python 2 or 3.
-
- .. deprecated:: 2.0
- """
- def __str__(self) -> str:
- warnings.warn('UnicodeMixin is deprecated',
- RemovedInSphinx40Warning, stacklevel=2)
- return self.__unicode__() # type: ignore
-
-
def execfile_(filepath: str, _globals: Any, open: Callable = open) -> None:
warnings.warn('execfile_() is deprecated',
RemovedInSphinx60Warning, stacklevel=2)
@@ -72,30 +47,5 @@ def execfile_(filepath: str, _globals: Any, open: Callable = open) -> None:
# compile to a code object, handle syntax errors
filepath_enc = filepath.encode(fs_encoding)
- try:
- code = compile(source, filepath_enc, 'exec')
- except SyntaxError:
- # maybe the file uses 2.x syntax; try to refactor to
- # 3.x syntax using 2to3
- source = convert_with_2to3(filepath)
- code = compile(source, filepath_enc, 'exec')
- # TODO: When support for evaluating Python 2 syntax is removed,
- # deprecate convert_with_2to3().
- logger.warning(__('Support for evaluating Python 2 syntax is deprecated '
- 'and will be removed in Sphinx 4.0. '
- 'Convert %s to Python 3 syntax.'),
- filepath)
+ code = compile(source, filepath_enc, 'exec')
exec(code, _globals)
-
-
-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/texescape.py b/sphinx/util/texescape.py
index afa1c349e..051370481 100644
--- a/sphinx/util/texescape.py
+++ b/sphinx/util/texescape.py
@@ -11,8 +11,6 @@
import re
from typing import Dict
-from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
-
tex_replacements = [
# map TeX special chars
@@ -109,14 +107,6 @@ _tex_hlescape_map = {} # type: Dict[int, str]
_tex_hlescape_map_without_unicode = {} # type: Dict[int, str]
-deprecated_alias('sphinx.util.texescape',
- {
- 'tex_escape_map': _tex_escape_map,
- 'tex_hl_escape_map_new': _tex_hlescape_map,
- },
- RemovedInSphinx40Warning)
-
-
def escape(s: str, latex_engine: str = None) -> str:
"""Escape text for LaTeX output."""
if latex_engine in ('lualatex', 'xelatex'):