diff --git a/setup.py b/setup.py index a427d5493..04f17d465 100644 --- a/setup.py +++ b/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': [ diff --git a/sphinx/config.py b/sphinx/config.py index 19a8f6c4f..73f7c51da 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -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', []), diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index e943cfb1e..52d0257e5 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -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) diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index d9853ff06..52c7b5ee7 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -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]: diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 98563f58e..d429be602 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -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: diff --git a/sphinx/util/images.py b/sphinx/util/images.py index 568682b37..396cb6161 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -54,7 +54,7 @@ def get_image_size(filename: str) -> Tuple[int, int]: def guess_mimetype_for_stream(stream: IO, default: str = None) -> str: - imgtype = imghdr.what(stream) # type: ignore + imgtype = imghdr.what(stream) if imgtype: return 'image/' + imgtype else: diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index bca6e0bfc..2277b78e6 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -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: diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 061bbcb6d..c7afdabb7 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -83,7 +83,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, diff --git a/sphinx/util/template.py b/sphinx/util/template.py index 1337f407c..08ca9d06d 100644 --- a/sphinx/util/template.py +++ b/sphinx/util/template.py @@ -25,7 +25,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) diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 08bf7203b..f23ed4ce1 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -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__) == 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]) else: 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 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) @@ -170,7 +170,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) == 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)