mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch '3.0.x' into 3.x
This commit is contained in:
commit
6a55947e9f
2
setup.py
2
setup.py
@ -44,7 +44,7 @@ extras_require = {
|
||||
'lint': [
|
||||
'flake8>=3.5.0',
|
||||
'flake8-import-order',
|
||||
'mypy>=0.770',
|
||||
'mypy>=0.780',
|
||||
'docutils-stubs',
|
||||
],
|
||||
'test': [
|
||||
|
@ -131,7 +131,7 @@ class Config:
|
||||
'rst_epilog': (None, 'env', [str]),
|
||||
'rst_prolog': (None, 'env', [str]),
|
||||
'trim_doctest_flags': (True, 'env', []),
|
||||
'primary_domain': ('py', 'env', [NoneType]), # type: ignore
|
||||
'primary_domain': ('py', 'env', [NoneType]),
|
||||
'needs_sphinx': (None, None, [str]),
|
||||
'needs_extensions': ({}, None, []),
|
||||
'manpages_url': (None, 'env', []),
|
||||
|
@ -186,7 +186,7 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader):
|
||||
self.environment.globals['accesskey'] = contextfunction(accesskey)
|
||||
self.environment.globals['idgen'] = idgen
|
||||
if use_i18n:
|
||||
self.environment.install_gettext_translations(builder.app.translator) # type: ignore # NOQA
|
||||
self.environment.install_gettext_translations(builder.app.translator)
|
||||
|
||||
def render(self, template: str, context: Dict) -> str: # type: ignore
|
||||
return self.environment.get_template(template).render(context)
|
||||
|
@ -297,8 +297,8 @@ class IndexBuilder:
|
||||
frozen.get('envversion') != self.env.version:
|
||||
raise ValueError('old format')
|
||||
index2fn = frozen['docnames']
|
||||
self._filenames = dict(zip(index2fn, frozen['filenames']))
|
||||
self._titles = dict(zip(index2fn, frozen['titles']))
|
||||
self._filenames = dict(zip(index2fn, frozen['filenames'])) # type: ignore
|
||||
self._titles = dict(zip(index2fn, frozen['titles'])) # type: ignore
|
||||
|
||||
def load_terms(mapping: Dict[str, Any]) -> Dict[str, Set[str]]:
|
||||
rv = {}
|
||||
@ -359,13 +359,13 @@ class IndexBuilder:
|
||||
def get_terms(self, fn2index: Dict) -> Tuple[Dict[str, List[str]], Dict[str, List[str]]]:
|
||||
rvs = {}, {} # type: Tuple[Dict[str, List[str]], Dict[str, List[str]]]
|
||||
for rv, mapping in zip(rvs, (self._mapping, self._title_mapping)):
|
||||
for k, v in mapping.items():
|
||||
for k, v in mapping.items(): # type: ignore
|
||||
if len(v) == 1:
|
||||
fn, = v
|
||||
if fn in fn2index:
|
||||
rv[k] = fn2index[fn]
|
||||
rv[k] = fn2index[fn] # type: ignore
|
||||
else:
|
||||
rv[k] = sorted([fn2index[fn] for fn in v if fn in fn2index])
|
||||
rv[k] = sorted([fn2index[fn] for fn in v if fn in fn2index]) # type: ignore # NOQA
|
||||
return rvs
|
||||
|
||||
def freeze(self) -> Dict[str, Any]:
|
||||
|
@ -35,8 +35,7 @@ def get_terminal_width() -> int:
|
||||
import termios
|
||||
import fcntl
|
||||
import struct
|
||||
call = fcntl.ioctl(0, termios.TIOCGWINSZ, # type: ignore
|
||||
struct.pack('hhhh', 0, 0, 0, 0))
|
||||
call = fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('hhhh', 0, 0, 0, 0))
|
||||
height, width = struct.unpack('hhhh', call)[:2]
|
||||
terminal_width = width
|
||||
except Exception:
|
||||
|
@ -54,7 +54,7 @@ def get_image_size(filename: str) -> Optional[Tuple[int, int]]:
|
||||
|
||||
|
||||
def guess_mimetype_for_stream(stream: IO, default: Optional[str] = None) -> Optional[str]:
|
||||
imgtype = imghdr.what(stream) # type: ignore
|
||||
imgtype = imghdr.what(stream)
|
||||
if imgtype:
|
||||
return 'image/' + imgtype
|
||||
else:
|
||||
|
@ -29,6 +29,7 @@ if False:
|
||||
# For type annotation
|
||||
from typing import Type # for python3.5.1
|
||||
from sphinx.builders import Builder
|
||||
from sphinx.domain import IndexEntry
|
||||
from sphinx.environment import BuildEnvironment
|
||||
from sphinx.utils.tags import Tags
|
||||
|
||||
@ -313,7 +314,7 @@ def get_prev_node(node: Node) -> Node:
|
||||
return None
|
||||
|
||||
|
||||
def traverse_translatable_index(doctree: Element) -> Iterable[Tuple[Element, List[str]]]:
|
||||
def traverse_translatable_index(doctree: Element) -> Iterable[Tuple[Element, List["IndexEntry"]]]: # NOQA
|
||||
"""Traverse translatable index node from a document tree."""
|
||||
for node in doctree.traverse(NodeMatcher(addnodes.index, inline=False)): # type: addnodes.index # NOQA
|
||||
if 'raw_entries' in node:
|
||||
|
@ -90,7 +90,7 @@ def execfile_(filepath: str, _globals: Any, open: Callable = open) -> None:
|
||||
|
||||
deprecated_alias('sphinx.util.pycompat',
|
||||
{
|
||||
'NoneType': NoneType, # type: ignore
|
||||
'NoneType': NoneType,
|
||||
'TextIOWrapper': io.TextIOWrapper,
|
||||
'htmlescape': html.escape,
|
||||
'indent': textwrap.indent,
|
||||
|
@ -28,7 +28,7 @@ class BaseRenderer:
|
||||
def __init__(self, loader: BaseLoader = None) -> None:
|
||||
self.env = SandboxedEnvironment(loader=loader, extensions=['jinja2.ext.i18n'])
|
||||
self.env.filters['repr'] = repr
|
||||
self.env.install_gettext_translations(get_translator()) # type: ignore
|
||||
self.env.install_gettext_translations(get_translator())
|
||||
|
||||
def render(self, template_name: str, context: Dict) -> str:
|
||||
return self.env.get_template(template_name).render(context)
|
||||
|
@ -53,7 +53,7 @@ def stringify(annotation: Any) -> str:
|
||||
return annotation.__name__
|
||||
elif not annotation:
|
||||
return repr(annotation)
|
||||
elif annotation is NoneType: # type: ignore
|
||||
elif annotation is NoneType:
|
||||
return 'None'
|
||||
elif (getattr(annotation, '__module__', None) == 'builtins' and
|
||||
hasattr(annotation, '__qualname__')):
|
||||
@ -91,7 +91,7 @@ def _stringify_py37(annotation: Any) -> str:
|
||||
|
||||
if getattr(annotation, '__args__', None):
|
||||
if qualname == 'Union':
|
||||
if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType: # type: ignore # NOQA
|
||||
if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType:
|
||||
if len(annotation.__args__) > 2:
|
||||
args = ', '.join(stringify(a) for a in annotation.__args__[:-1])
|
||||
return 'Optional[Union[%s]]' % args
|
||||
@ -165,7 +165,7 @@ def _stringify_py36(annotation: Any) -> str:
|
||||
hasattr(annotation, '__union_params__')): # for Python 3.5
|
||||
params = annotation.__union_params__
|
||||
if params is not None:
|
||||
if len(params) == 2 and params[1] is NoneType: # type: ignore
|
||||
if len(params) == 2 and params[1] is NoneType:
|
||||
return 'Optional[%s]' % stringify(params[0])
|
||||
else:
|
||||
param_str = ', '.join(stringify(p) for p in params)
|
||||
@ -174,7 +174,7 @@ def _stringify_py36(annotation: Any) -> str:
|
||||
annotation.__origin__ is typing.Union): # for Python 3.5.2+
|
||||
params = annotation.__args__
|
||||
if params is not None:
|
||||
if len(params) > 1 and params[-1] is NoneType: # type: ignore
|
||||
if len(params) > 1 and params[-1] is NoneType:
|
||||
if len(params) > 2:
|
||||
param_str = ", ".join(stringify(p) for p in params[:-1])
|
||||
return 'Optional[Union[%s]]' % param_str
|
||||
|
Loading…
Reference in New Issue
Block a user