From 579a79660e843cd86278832c9aad3fec8f8a5fb3 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 7 May 2017 14:09:54 +0900 Subject: [PATCH] Update type annotations for new mypy --- mypy.ini | 1 - sphinx/__init__.py | 2 +- sphinx/builders/applehelp.py | 2 +- sphinx/builders/gettext.py | 4 ++-- sphinx/builders/html.py | 6 +++--- sphinx/builders/linkcheck.py | 6 +++--- sphinx/builders/qthelp.py | 4 ++-- sphinx/ext/autodoc.py | 2 +- sphinx/ext/autosummary/generate.py | 5 ++--- sphinx/ext/doctest.py | 2 +- sphinx/ext/ifconfig.py | 2 +- sphinx/ext/inheritance_diagram.py | 2 +- sphinx/quickstart.py | 2 +- sphinx/registry.py | 2 +- sphinx/search/ja.py | 6 +++--- sphinx/transforms/__init__.py | 2 +- sphinx/util/fileutil.py | 2 +- sphinx/util/images.py | 2 +- sphinx/util/parallel.py | 2 +- sphinx/util/pycompat.py | 2 +- sphinx/util/requests.py | 2 +- sphinx/writers/latex.py | 2 +- sphinx/writers/manpage.py | 2 +- sphinx/writers/texinfo.py | 2 +- sphinx/writers/text.py | 2 +- 25 files changed, 33 insertions(+), 35 deletions(-) diff --git a/mypy.ini b/mypy.ini index 8fbf24f303..ec12ea587e 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2,7 +2,6 @@ python_version = 2.7 ignore_missing_imports = True follow_imports = skip -fast_parser = True incremental = True check_untyped_defs = True warn_unused_ignores = True diff --git a/sphinx/__init__.py b/sphinx/__init__.py index cd8ad2c0d3..f8ee222c38 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -58,7 +58,7 @@ if __version__.endswith('+'): stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if out: - __display_version__ += '/' + out.decode().strip() # type: ignore + __display_version__ += '/' + out.decode().strip() except Exception: pass diff --git a/sphinx/builders/applehelp.py b/sphinx/builders/applehelp.py index fa47429e26..f8df9310c1 100644 --- a/sphinx/builders/applehelp.py +++ b/sphinx/builders/applehelp.py @@ -190,7 +190,7 @@ class AppleHelpBuilder(StandaloneHTMLBuilder): # Build the access page logger.info(bold('building access page...'), nonl=True) - with codecs.open(path.join(language_dir, '_access.html'), 'w') as f: + with codecs.open(path.join(language_dir, '_access.html'), 'w') as f: # type: ignore f.write(access_page_template % { 'toc': htmlescape(toc, quote=True), 'title': htmlescape(self.config.applehelp_title) diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 4da19bd2c5..b684104c1c 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -31,7 +31,7 @@ from sphinx.locale import pairindextypes if False: # For type annotation - from typing import Any, Dict, Iterable, List, Set, Tuple # NOQA + from typing import Any, DefaultDict, Dict, Iterable, List, Set, Tuple # NOQA from docutils import nodes # NOQA from sphinx.util.i18n import CatalogInfo # NOQA from sphinx.application import Sphinx # NOQA @@ -122,7 +122,7 @@ class I18nBuilder(Builder): self.env.set_versioning_method(self.versioning_method, self.env.config.gettext_uuid) self.tags = I18nTags() - self.catalogs = defaultdict(Catalog) # type: defaultdict[unicode, Catalog] + self.catalogs = defaultdict(Catalog) # type: DefaultDict[unicode, Catalog] def get_target_uri(self, docname, typ=None): # type: (unicode, unicode) -> unicode diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index c98f5fee81..c8ca51c876 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -390,7 +390,7 @@ class StandaloneHTMLBuilder(Builder): # typically doesn't include the time of day lufmt = self.config.html_last_updated_fmt if lufmt is not None: - self.last_updated = format_date(lufmt or _('%b %d, %Y'), + self.last_updated = format_date(lufmt or _('%b %d, %Y'), # type: ignore language=self.config.language) else: self.last_updated = None @@ -823,7 +823,7 @@ class StandaloneHTMLBuilder(Builder): else: f = open(searchindexfn, 'rb') # type: ignore with f: - self.indexer.load(f, self.indexer_format) # type: ignore + self.indexer.load(f, self.indexer_format) except (IOError, OSError, ValueError): if keep: logger.warning('search index couldn\'t be loaded, but not all ' @@ -993,7 +993,7 @@ class StandaloneHTMLBuilder(Builder): else: f = open(searchindexfn + '.tmp', 'wb') # type: ignore with f: - self.indexer.dump(f, self.indexer_format) # type: ignore + self.indexer.dump(f, self.indexer_format) movefile(searchindexfn + '.tmp', searchindexfn) logger.info('done') diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 722041d5b0..c52b808cd7 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -16,7 +16,7 @@ import threading from os import path from requests.exceptions import HTTPError -from six.moves import queue, html_parser # type: ignore +from six.moves import queue, html_parser from six.moves.urllib.parse import unquote from docutils import nodes @@ -105,8 +105,8 @@ class CheckExternalLinksBuilder(Builder): open(path.join(self.outdir, 'output.txt'), 'w').close() # create queues and worker threads - self.wqueue = queue.Queue() - self.rqueue = queue.Queue() + self.wqueue = queue.Queue() # type: queue.Queue + self.rqueue = queue.Queue() # type: queue.Queue self.workers = [] # type: List[threading.Thread] for i in range(self.app.config.linkcheck_workers): thread = threading.Thread(target=self.check_thread) diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py index ac31177333..b1c94c5484 100644 --- a/sphinx/builders/qthelp.py +++ b/sphinx/builders/qthelp.py @@ -206,7 +206,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder): # write the project file with codecs.open(path.join(outdir, outname + '.qhp'), 'w', 'utf-8') as f: # type: ignore # NOQA - f.write(project_template % { # type: ignore + f.write(project_template % { 'outname': htmlescape(outname), 'title': htmlescape(self.config.html_title), 'version': htmlescape(self.config.version), @@ -223,7 +223,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder): logger.info('writing collection project file...') with codecs.open(path.join(outdir, outname + '.qhcp'), 'w', 'utf-8') as f: # type: ignore # NOQA - f.write(collection_template % { # type: ignore + f.write(collection_template % { 'outname': htmlescape(outname), 'title': htmlescape(self.config.html_short_title), 'homepage': htmlescape(homepage), diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 58c7317a37..1b314bd0ec 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -48,7 +48,7 @@ try: if sys.version_info >= (3,): import typing else: - typing = None # type: ignore + typing = None except ImportError: typing = None diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 3dd4a2fcfd..d40b4787dd 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -259,8 +259,7 @@ def find_autosummary_in_files(filenames): with codecs.open(filename, 'r', encoding='utf-8', # type: ignore errors='ignore') as f: lines = f.read().splitlines() - documented.extend(find_autosummary_in_lines(lines, # type: ignore - filename=filename)) + documented.extend(find_autosummary_in_lines(lines, filename=filename)) return documented @@ -273,7 +272,7 @@ def find_autosummary_in_docstring(name, module=None, filename=None): try: real_name, obj, parent, modname = import_by_name(name) lines = pydoc.getdoc(obj).splitlines() - return find_autosummary_in_lines(lines, module=name, filename=filename) + return find_autosummary_in_lines(lines, module=name, filename=filename) # type: ignore except AttributeError: pass except ImportError as e: diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 27672ff435..42363fdfd5 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -307,7 +307,7 @@ class DocTestBuilder(Builder): self.outfile = None # type: IO self.outfile = codecs.open(path.join(self.outdir, 'output.txt'), # type: ignore 'w', encoding='utf-8') - self.outfile.write(('Results of doctest builder run on %s\n' # type: ignore + self.outfile.write(('Results of doctest builder run on %s\n' '==================================%s\n') % (date, '=' * len(date))) diff --git a/sphinx/ext/ifconfig.py b/sphinx/ext/ifconfig.py index 036cbdf674..c700649ddd 100644 --- a/sphinx/ext/ifconfig.py +++ b/sphinx/ext/ifconfig.py @@ -66,7 +66,7 @@ def process_ifconfig_nodes(app, doctree, docname): except Exception as err: # handle exceptions in a clean fashion from traceback import format_exception_only - msg = ''.join(format_exception_only(err.__class__, err)) # type: ignore + msg = ''.join(format_exception_only(err.__class__, err)) newnode = doctree.reporter.error('Exception occured in ' 'ifconfig expression: \n%s' % msg, base_node=node) diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 09b60655d0..f5b0228a5f 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -42,7 +42,7 @@ import inspect try: from hashlib import md5 except ImportError: - from md5 import md5 # type: ignore + from md5 import md5 from six import text_type from six.moves import builtins diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py index 50d200e60f..e70de64b6a 100644 --- a/sphinx/quickstart.py +++ b/sphinx/quickstart.py @@ -557,7 +557,7 @@ def valid_dir(d): class MyFormatter(optparse.IndentedHelpFormatter): - def format_usage(self, usage): + def format_usage(self, usage): # type: ignore # type: (str) -> str return usage diff --git a/sphinx/registry.py b/sphinx/registry.py index a86fd8915f..2efd5e08a3 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -133,7 +133,7 @@ class SphinxComponentRegistry(object): directive = type(directivename, # type: ignore (GenericObject, object), {'indextemplate': indextemplate, - 'parse_node': staticmethod(parse_node), # type: ignore + 'parse_node': staticmethod(parse_node), 'doc_field_types': doc_field_types}) stddomain = self.domains['std'] diff --git a/sphinx/search/ja.py b/sphinx/search/ja.py index a2703441b8..d1d922dd41 100644 --- a/sphinx/search/ja.py +++ b/sphinx/search/ja.py @@ -41,7 +41,7 @@ from sphinx.util import import_object if False: # For type annotation - from typing import Dict, List # NOQA + from typing import Any, Dict, List # NOQA class BaseSplitter(object): @@ -65,8 +65,8 @@ class MecabSplitter(BaseSplitter): def __init__(self, options): # type: (Dict) -> None super(MecabSplitter, self).__init__(options) - self.ctypes_libmecab = None # type: ignore - self.ctypes_mecab = None # type: ignore + self.ctypes_libmecab = None # type: Any + self.ctypes_mecab = None # type: Any if not native_module: self.init_ctypes(options) else: diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index a60b717b9c..5109a530ce 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -116,7 +116,7 @@ class DefaultSubstitutions(SphinxTransform): text = self.config[refname] if refname == 'today' and not text: # special handling: can also specify a strftime format - text = format_date(self.config.today_fmt or _('%b %d, %Y'), + text = format_date(self.config.today_fmt or _('%b %d, %Y'), # type: ignore language=self.config.language) ref.replace_self(nodes.Text(text, text)) diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py index 772e413318..04fd338b72 100644 --- a/sphinx/util/fileutil.py +++ b/sphinx/util/fileutil.py @@ -51,7 +51,7 @@ def copy_asset_file(source, destination, context=None, renderer=None): if destination.lower().endswith('_t'): destination = destination[:-2] with codecs.open(destination, 'w', encoding='utf-8') as fdst: # type: ignore - fdst.write(renderer.render_string(fsrc.read(), context)) # type: ignore + fdst.write(renderer.render_string(fsrc.read(), context)) else: copyfile(source, destination) diff --git a/sphinx/util/images.py b/sphinx/util/images.py index 7bb904d22d..2d228e66de 100644 --- a/sphinx/util/images.py +++ b/sphinx/util/images.py @@ -118,5 +118,5 @@ def parse_data_uri(uri): elif prop: mimetype = prop - image_data = base64.b64decode(data) # type: ignore + image_data = base64.b64decode(data) return DataURI(mimetype, charset, image_data) diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index bcc6117f67..7ca4e94e6d 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -88,7 +88,7 @@ class ParallelTasks(object): failed = False except BaseException as err: failed = True - errmsg = traceback.format_exception_only(err.__class__, err)[0].strip() # type: ignore # NOQA + errmsg = traceback.format_exception_only(err.__class__, err)[0].strip() ret = (errmsg, traceback.format_exc()) logging.convert_serializable(collector.logs) pipe.send((failed, collector.logs, ret)) diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 5a1fda9093..6122c16975 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -79,7 +79,7 @@ if PY3: return text_type(tree) else: # no need to refactor on 2.x versions - convert_with_2to3 = None # type: ignore + convert_with_2to3 = None # htmlescape() diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py index 6834e63687..3dc1a30b24 100644 --- a/sphinx/util/requests.py +++ b/sphinx/util/requests.py @@ -120,7 +120,7 @@ def _get_tls_cacert(url, config): certs = getattr(config, 'tls_cacerts', None) if not certs: return True - elif isinstance(certs, (string_types, tuple)): # type: ignore + elif isinstance(certs, (string_types, tuple)): return certs # type: ignore else: hostname = urlsplit(url)[1] diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 5dea34c547..728d5c94eb 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -557,7 +557,7 @@ class LaTeXTranslator(nodes.NodeVisitor): if builder.config.today: self.elements['date'] = builder.config.today else: - self.elements['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'), + self.elements['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'), # type: ignore # NOQA language=builder.config.language) if builder.config.latex_logo: # no need for \\noindent here, used in flushright diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 830b1148a2..71c2aac0b8 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -107,7 +107,7 @@ class ManualPageTranslator(BaseTranslator): if builder.config.today: self._docinfo['date'] = builder.config.today else: - self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'), + self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'), # type: ignore # NOQA language=builder.config.language) self._docinfo['copyright'] = builder.config.copyright self._docinfo['version'] = builder.config.version diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 13fac45d32..d7e08510e8 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -238,7 +238,7 @@ class TexinfoTranslator(nodes.NodeVisitor): 'project': self.escape(self.builder.config.project), 'copyright': self.escape(self.builder.config.copyright), 'date': self.escape(self.builder.config.today or - format_date(self.builder.config.today_fmt or _('%b %d, %Y'), + format_date(self.builder.config.today_fmt or _('%b %d, %Y'), # type: ignore # NOQA language=self.builder.config.language)) }) # title diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 687eecfd77..d2b2f9045c 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -661,7 +661,7 @@ class TextTranslator(nodes.NodeVisitor): self.add_text(''.join(out) + self.nl) def writerow(row): - # type: (list[List[unicode]]) -> None + # type: (List[List[unicode]]) -> None lines = zip_longest(*row) for line in lines: out = ['|']