mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Replace six.string_types with native str
This commit is contained in:
parent
c4df9b5de2
commit
b8631079bf
@ -13,8 +13,6 @@
|
||||
from collections import namedtuple
|
||||
from os import path
|
||||
|
||||
from six import string_types
|
||||
|
||||
from sphinx import package_dir
|
||||
from sphinx.builders import _epub_base
|
||||
from sphinx.config import string_classes, ENUM
|
||||
@ -234,7 +232,7 @@ def convert_epub_css_files(app, config):
|
||||
"""This converts string styled epub_css_files to tuple styled one."""
|
||||
epub_css_files = [] # type: List[Tuple[unicode, Dict]]
|
||||
for entry in config.epub_css_files:
|
||||
if isinstance(entry, string_types):
|
||||
if isinstance(entry, str):
|
||||
epub_css_files.append((entry, {}))
|
||||
else:
|
||||
try:
|
||||
|
@ -25,7 +25,7 @@ from docutils.frontend import OptionParser
|
||||
from docutils.io import DocTreeInput, StringOutput
|
||||
from docutils.readers.doctree import Reader as DoctreeReader
|
||||
from docutils.utils import relative_path
|
||||
from six import text_type, string_types
|
||||
from six import text_type
|
||||
|
||||
from sphinx import package_dir, __display_version__
|
||||
from sphinx.application import ENV_PICKLE_FILENAME
|
||||
@ -531,7 +531,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
favicon = self.config.html_favicon and \
|
||||
path.basename(self.config.html_favicon) or ''
|
||||
|
||||
if not isinstance(self.config.html_use_opensearch, string_types):
|
||||
if not isinstance(self.config.html_use_opensearch, str):
|
||||
logger.warning(__('html_use_opensearch config value must now be a string'))
|
||||
|
||||
self.relations = self.env.collect_relations()
|
||||
@ -1533,7 +1533,7 @@ def convert_html_css_files(app, config):
|
||||
"""This converts string styled html_css_files to tuple styled one."""
|
||||
html_css_files = [] # type: List[Tuple[unicode, Dict]]
|
||||
for entry in config.html_css_files:
|
||||
if isinstance(entry, string_types):
|
||||
if isinstance(entry, str):
|
||||
html_css_files.append((entry, {}))
|
||||
else:
|
||||
try:
|
||||
@ -1551,7 +1551,7 @@ def convert_html_js_files(app, config):
|
||||
"""This converts string styled html_js_files to tuple styled one."""
|
||||
html_js_files = [] # type: List[Tuple[unicode, Dict]]
|
||||
for entry in config.html_js_files:
|
||||
if isinstance(entry, string_types):
|
||||
if isinstance(entry, str):
|
||||
html_js_files.append((entry, {}))
|
||||
else:
|
||||
try:
|
||||
|
@ -13,7 +13,6 @@ from os import path
|
||||
|
||||
from docutils.frontend import OptionParser
|
||||
from docutils.io import FileOutput
|
||||
from six import string_types
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.builders import Builder
|
||||
@ -77,7 +76,7 @@ class ManualPageBuilder(Builder):
|
||||
logger.warning(__('"man_pages" config value references unknown '
|
||||
'document %s'), docname)
|
||||
continue
|
||||
if isinstance(authors, string_types):
|
||||
if isinstance(authors, str):
|
||||
if authors:
|
||||
authors = [authors]
|
||||
else:
|
||||
|
@ -17,7 +17,7 @@ from collections import OrderedDict
|
||||
from os import path, getenv
|
||||
from typing import Any, NamedTuple, Union
|
||||
|
||||
from six import string_types, text_type, integer_types
|
||||
from six import text_type, integer_types
|
||||
|
||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||
from sphinx.errors import ConfigError, ExtensionError
|
||||
@ -183,7 +183,7 @@ class Config:
|
||||
self.setup = config.get('setup', None) # type: Callable
|
||||
|
||||
if 'extensions' in overrides:
|
||||
if isinstance(overrides['extensions'], string_types):
|
||||
if isinstance(overrides['extensions'], str):
|
||||
config['extensions'] = overrides.pop('extensions').split(',')
|
||||
else:
|
||||
config['extensions'] = overrides.pop('extensions')
|
||||
@ -211,7 +211,7 @@ class Config:
|
||||
|
||||
def convert_overrides(self, name, value):
|
||||
# type: (unicode, Any) -> Any
|
||||
if not isinstance(value, string_types):
|
||||
if not isinstance(value, str):
|
||||
return value
|
||||
else:
|
||||
defvalue = self.values[name][0]
|
||||
@ -231,7 +231,7 @@ class Config:
|
||||
(value, name))
|
||||
elif hasattr(defvalue, '__call__'):
|
||||
return value
|
||||
elif defvalue is not None and not isinstance(defvalue, string_types):
|
||||
elif defvalue is not None and not isinstance(defvalue, str):
|
||||
raise ValueError(__('cannot override config setting %r with unsupported '
|
||||
'type, ignoring') % name)
|
||||
else:
|
||||
@ -265,7 +265,7 @@ class Config:
|
||||
logger.warning(__('unknown config value %r in override, ignoring'),
|
||||
valname)
|
||||
continue
|
||||
if isinstance(value, string_types):
|
||||
if isinstance(value, str):
|
||||
config[valname] = self.convert_overrides(valname, value)
|
||||
else:
|
||||
config[valname] = value
|
||||
@ -316,7 +316,7 @@ class Config:
|
||||
|
||||
def filter(self, rebuild):
|
||||
# type: (Union[unicode, List[unicode]]) -> Iterator[ConfigValue]
|
||||
if isinstance(rebuild, string_types):
|
||||
if isinstance(rebuild, str):
|
||||
rebuild = [rebuild]
|
||||
return (value for value in self if value.rebuild in rebuild)
|
||||
|
||||
@ -383,7 +383,7 @@ def convert_source_suffix(app, config):
|
||||
* new style: a dict which maps from fileext to filetype
|
||||
"""
|
||||
source_suffix = config.source_suffix
|
||||
if isinstance(source_suffix, string_types):
|
||||
if isinstance(source_suffix, str):
|
||||
# if str, considers as default filetype (None)
|
||||
#
|
||||
# The default filetype is determined on later step.
|
||||
|
@ -18,7 +18,7 @@ import warnings
|
||||
from typing import Any
|
||||
|
||||
from docutils.statemachine import ViewList
|
||||
from six import text_type, string_types
|
||||
from six import text_type
|
||||
|
||||
import sphinx
|
||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||
@ -836,7 +836,7 @@ class ModuleDocumenter(Documenter):
|
||||
memberlist = self.object.__all__
|
||||
# Sometimes __all__ is broken...
|
||||
if not isinstance(memberlist, (list, tuple)) or not \
|
||||
all(isinstance(entry, string_types) for entry in memberlist):
|
||||
all(isinstance(entry, str) for entry in memberlist):
|
||||
logger.warning(
|
||||
__('__all__ should be a list of strings, not %r '
|
||||
'(in module %s) -- ignoring __all__') %
|
||||
@ -1460,7 +1460,7 @@ def merge_autodoc_default_flags(app, config):
|
||||
RemovedInSphinx30Warning, stacklevel=2)
|
||||
|
||||
for option in config.autodoc_default_flags:
|
||||
if isinstance(option, string_types):
|
||||
if isinstance(option, str):
|
||||
config.autodoc_default_options[option] = None
|
||||
else:
|
||||
logger.warning(
|
||||
|
@ -64,7 +64,6 @@ from docutils import nodes
|
||||
from docutils.parsers.rst import directives
|
||||
from docutils.parsers.rst.states import RSTStateMachine, state_classes
|
||||
from docutils.statemachine import ViewList
|
||||
from six import string_types
|
||||
from six import text_type
|
||||
|
||||
import sphinx
|
||||
@ -642,8 +641,8 @@ def get_rst_suffix(app):
|
||||
parser_class = app.registry.get_source_parsers().get(suffix)
|
||||
if parser_class is None:
|
||||
return ('restructuredtext',)
|
||||
if isinstance(parser_class, string_types):
|
||||
parser_class = import_object(parser_class, 'source parser') # type: ignore
|
||||
if isinstance(parser_class, str):
|
||||
parser_class = import_object(parser_class, 'source parser')
|
||||
return parser_class.supported
|
||||
|
||||
suffix = None # type: unicode
|
||||
|
@ -35,7 +35,7 @@ from urllib.parse import urlsplit, urlunsplit
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.utils import relative_path
|
||||
from six import string_types, text_type
|
||||
from six import text_type
|
||||
|
||||
import sphinx
|
||||
from sphinx.builders.html import INVENTORY_FILENAME
|
||||
@ -217,7 +217,7 @@ def load_mappings(app):
|
||||
if isinstance(value, (list, tuple)):
|
||||
# new format
|
||||
name, (uri, inv) = key, value
|
||||
if not isinstance(name, string_types):
|
||||
if not isinstance(name, str):
|
||||
logger.warning(__('intersphinx identifier %r is not string. Ignored'), name)
|
||||
continue
|
||||
else:
|
||||
|
@ -16,8 +16,6 @@ import re
|
||||
from collections.abc import Callable
|
||||
from functools import partial
|
||||
|
||||
from six import string_types
|
||||
|
||||
from sphinx.ext.napoleon.iterators import modify_iter
|
||||
from sphinx.locale import _
|
||||
from sphinx.util.pycompat import UnicodeMixin
|
||||
@ -132,10 +130,11 @@ class GoogleDocstring(UnicodeMixin):
|
||||
self._name = name
|
||||
self._obj = obj
|
||||
self._opt = options
|
||||
if isinstance(docstring, string_types):
|
||||
docstring = docstring.splitlines()
|
||||
self._lines = docstring
|
||||
self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
|
||||
if isinstance(docstring, str):
|
||||
lines = docstring.splitlines()
|
||||
else:
|
||||
lines = docstring # type: ignore
|
||||
self._line_iter = modify_iter(lines, modifier=lambda s: s.rstrip())
|
||||
self._parsed_lines = [] # type: List[unicode]
|
||||
self._is_in_section = False
|
||||
self._section_indent = 0
|
||||
@ -543,7 +542,7 @@ class GoogleDocstring(UnicodeMixin):
|
||||
|
||||
if self._config.napoleon_custom_sections is not None:
|
||||
for entry in self._config.napoleon_custom_sections:
|
||||
if isinstance(entry, string_types):
|
||||
if isinstance(entry, str):
|
||||
# if entry is just a label, add to sections list,
|
||||
# using generic section logic.
|
||||
self._sections[entry.lower()] = self._parse_custom_generic_section
|
||||
@ -961,7 +960,7 @@ class NumpyDocstring(GoogleDocstring):
|
||||
# type: () -> bool
|
||||
section, underline = self._line_iter.peek(2)
|
||||
section = section.lower()
|
||||
if section in self._sections and isinstance(underline, string_types):
|
||||
if section in self._sections and isinstance(underline, str):
|
||||
return bool(_numpy_section_regex.match(underline))
|
||||
elif self._directive_sections:
|
||||
if _directive_regex.match(section):
|
||||
|
@ -17,7 +17,6 @@ from jinja2 import FileSystemLoader, BaseLoader, TemplateNotFound, \
|
||||
contextfunction
|
||||
from jinja2.sandbox import SandboxedEnvironment
|
||||
from jinja2.utils import open_if_exists
|
||||
from six import string_types
|
||||
|
||||
from sphinx.application import TemplateBridge
|
||||
from sphinx.util import logging
|
||||
@ -33,7 +32,7 @@ if False:
|
||||
|
||||
def _tobool(val):
|
||||
# type: (unicode) -> bool
|
||||
if isinstance(val, string_types):
|
||||
if isinstance(val, str):
|
||||
return val.lower() in ('true', '1', 'yes', 'on')
|
||||
return bool(val)
|
||||
|
||||
|
@ -12,7 +12,7 @@ import pickle
|
||||
import re
|
||||
from os import path
|
||||
|
||||
from six import text_type, string_types
|
||||
from six import text_type
|
||||
|
||||
from docutils.nodes import raw, comment, title, Text, NodeVisitor, SkipNode
|
||||
|
||||
@ -291,7 +291,7 @@ class IndexBuilder:
|
||||
def load(self, stream, format):
|
||||
# type: (IO, Any) -> None
|
||||
"""Reconstruct from frozen data."""
|
||||
if isinstance(format, string_types):
|
||||
if isinstance(format, str):
|
||||
format = self.formats[format]
|
||||
frozen = format.load(stream)
|
||||
# if an old index is present, we treat it as not existing.
|
||||
@ -319,7 +319,7 @@ class IndexBuilder:
|
||||
def dump(self, stream, format):
|
||||
# type: (IO, Any) -> None
|
||||
"""Dump the frozen index to a stream."""
|
||||
if isinstance(format, string_types):
|
||||
if isinstance(format, str):
|
||||
format = self.formats[format]
|
||||
format.dump(self.freeze(), stream)
|
||||
|
||||
|
@ -18,7 +18,7 @@ import sys
|
||||
from distutils.cmd import Command
|
||||
from distutils.errors import DistutilsOptionError, DistutilsExecError
|
||||
|
||||
from six import StringIO, string_types
|
||||
from six import StringIO
|
||||
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.cmd.build import handle_exception
|
||||
@ -129,7 +129,7 @@ class BuildDoc(Command):
|
||||
if val is None:
|
||||
setattr(self, option, default)
|
||||
return default
|
||||
elif not isinstance(val, string_types):
|
||||
elif not isinstance(val, str):
|
||||
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
|
||||
% (option, what, val))
|
||||
return val
|
||||
|
@ -17,7 +17,7 @@ from collections import namedtuple
|
||||
from tempfile import gettempdir
|
||||
|
||||
import pytest
|
||||
from six import StringIO, string_types
|
||||
from six import StringIO
|
||||
|
||||
from . import util
|
||||
|
||||
@ -102,8 +102,7 @@ def test_params(request):
|
||||
}
|
||||
result.update(kwargs)
|
||||
|
||||
if (result['shared_result'] and
|
||||
not isinstance(result['shared_result'], string_types)):
|
||||
if (result['shared_result'] and not isinstance(result['shared_result'], str)):
|
||||
raise pytest.Exception('You can only provide a string type of value '
|
||||
'for "shared_result" ')
|
||||
return result
|
||||
|
@ -16,7 +16,6 @@ from xml.etree import ElementTree
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import directives, roles
|
||||
from six import string_types
|
||||
|
||||
from sphinx import application, locale
|
||||
from sphinx.builders.latex import LaTeXBuilder
|
||||
@ -74,7 +73,7 @@ def assert_node(node, cls=None, xpath="", **kwargs):
|
||||
for i, nodecls in enumerate(cls):
|
||||
path = xpath + "[%d]" % i
|
||||
assert_node(node[i], nodecls, xpath=path, **kwargs)
|
||||
elif isinstance(cls, string_types):
|
||||
elif isinstance(cls, str):
|
||||
assert node == cls, 'The node %r is not %r: %r' % (xpath, cls, node)
|
||||
else:
|
||||
assert isinstance(node, cls), \
|
||||
|
@ -15,7 +15,6 @@ import sys
|
||||
import warnings
|
||||
|
||||
from docutils.utils import get_source_line
|
||||
from six import string_types
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||
@ -36,8 +35,8 @@ def deprecate_source_parsers(app, config):
|
||||
'Please use app.add_source_parser() API instead.',
|
||||
RemovedInSphinx30Warning)
|
||||
for suffix, parser in config.source_parsers.items():
|
||||
if isinstance(parser, string_types):
|
||||
parser = import_object(parser, 'source parser') # type: ignore
|
||||
if isinstance(parser, str):
|
||||
parser = import_object(parser, 'source parser')
|
||||
app.add_source_parser(suffix, parser)
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ import sys
|
||||
import typing
|
||||
from functools import partial
|
||||
|
||||
from six import StringIO, string_types
|
||||
from six import StringIO
|
||||
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.pycompat import NoneType
|
||||
@ -381,8 +381,7 @@ class Signature:
|
||||
param.KEYWORD_ONLY):
|
||||
arg.write(param.name)
|
||||
if param.annotation is not param.empty:
|
||||
if isinstance(param.annotation, string_types) and \
|
||||
param.name in self.annotations:
|
||||
if isinstance(param.annotation, str) and param.name in self.annotations:
|
||||
arg.write(': ')
|
||||
arg.write(self.format_annotation(self.annotations[param.name]))
|
||||
else:
|
||||
@ -424,8 +423,8 @@ class Signature:
|
||||
|
||||
Displaying complex types from ``typing`` relies on its private API.
|
||||
"""
|
||||
if isinstance(annotation, string_types):
|
||||
return annotation # type: ignore
|
||||
if isinstance(annotation, str):
|
||||
return annotation
|
||||
elif isinstance(annotation, typing.TypeVar): # type: ignore
|
||||
return annotation.__name__
|
||||
elif not annotation:
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
import re
|
||||
|
||||
from six import integer_types, string_types
|
||||
from six import integer_types
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
@ -84,7 +84,7 @@ double in super""".split())
|
||||
def dumps(obj, key=False):
|
||||
# type: (Any, bool) -> str
|
||||
if key:
|
||||
if not isinstance(obj, string_types):
|
||||
if not isinstance(obj, str):
|
||||
obj = str(obj)
|
||||
if _nameonly_re.match(obj) and obj not in reswords:
|
||||
return obj # return it as a bare word
|
||||
@ -105,8 +105,8 @@ def dumps(obj, key=False):
|
||||
return '[%s]' % ','.join(sorted(dumps(x) for x in obj))
|
||||
elif isinstance(obj, (tuple, list)):
|
||||
return '[%s]' % ','.join(dumps(x) for x in obj)
|
||||
elif isinstance(obj, string_types):
|
||||
return encode_string(obj) # type: ignore
|
||||
elif isinstance(obj, str):
|
||||
return encode_string(obj)
|
||||
raise TypeError(type(obj))
|
||||
|
||||
|
||||
|
@ -17,7 +17,6 @@ from urllib.parse import urlsplit
|
||||
|
||||
import pkg_resources
|
||||
import requests
|
||||
from six import string_types
|
||||
|
||||
try:
|
||||
from requests.packages.urllib3.exceptions import SSLError
|
||||
@ -120,7 +119,7 @@ def _get_tls_cacert(url, config):
|
||||
certs = getattr(config, 'tls_cacerts', None)
|
||||
if not certs:
|
||||
return True
|
||||
elif isinstance(certs, (string_types, tuple)):
|
||||
elif isinstance(certs, (str, tuple)):
|
||||
return certs # type: ignore
|
||||
else:
|
||||
hostname = urlsplit(url)[1]
|
||||
|
@ -17,7 +17,6 @@ import warnings
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator
|
||||
from six import string_types
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.deprecation import RemovedInSphinx30Warning
|
||||
@ -81,7 +80,7 @@ class HTMLTranslator(BaseTranslator):
|
||||
self.protect_literal_text = 0
|
||||
self.permalink_text = builder.config.html_add_permalinks
|
||||
# support backwards-compatible setting to a bool
|
||||
if not isinstance(self.permalink_text, string_types):
|
||||
if not isinstance(self.permalink_text, str):
|
||||
self.permalink_text = self.permalink_text and u'\u00B6' or ''
|
||||
self.permalink_text = self.encode(self.permalink_text)
|
||||
self.secnumber_suffix = builder.config.html_secnumber_suffix
|
||||
|
@ -16,7 +16,6 @@ import warnings
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.writers.html5_polyglot import HTMLTranslator as BaseTranslator
|
||||
from six import string_types
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.deprecation import RemovedInSphinx30Warning
|
||||
@ -51,7 +50,7 @@ class HTML5Translator(BaseTranslator):
|
||||
self.protect_literal_text = 0
|
||||
self.permalink_text = builder.config.html_add_permalinks
|
||||
# support backwards-compatible setting to a bool
|
||||
if not isinstance(self.permalink_text, string_types):
|
||||
if not isinstance(self.permalink_text, str):
|
||||
self.permalink_text = self.permalink_text and u'\u00B6' or ''
|
||||
self.permalink_text = self.encode(self.permalink_text)
|
||||
self.secnumber_suffix = builder.config.html_secnumber_suffix
|
||||
|
Loading…
Reference in New Issue
Block a user