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