From fa77fe8ac9791814ea89a253c792218cbac5eba8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 15 Jul 2017 16:44:53 +0900 Subject: [PATCH] Fix mypy violations (for mypy-0.520) --- sphinx/application.py | 2 +- sphinx/ext/autodoc.py | 2 +- sphinx/ext/doctest.py | 32 ++++++++++++++++---------------- sphinx/roles.py | 2 +- sphinx/testing/util.py | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 27dfeb2e4..a205c7d5c 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -250,7 +250,7 @@ class Sphinx(object): user_locale_dirs, self.config.language, domains=['sphinx'], charset=self.config.source_encoding): catinfo.write_mo(self.config.language) - locale_dirs = [None, path.join(package_dir, 'locale')] + user_locale_dirs + locale_dirs = [None, path.join(package_dir, 'locale')] + user_locale_dirs # type: ignore else: locale_dirs = [] self.translator, has_translation = locale.init(locale_dirs, self.config.language) diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index c50b55387..4af2bb3c6 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -851,7 +851,7 @@ class Documenter(object): self.add_line(line, src[0], src[1]) def get_object_members(self, want_all): - # type: (bool) -> Tuple[bool, List[Tuple[unicode, object]]] + # type: (bool) -> Tuple[bool, List[Tuple[unicode, Any]]] """Return `(members_check_module, members)` where `members` is a list of `(membername, member)` pairs of the members of *self.object*. diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 42363fdfd..4110d9c90 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -134,12 +134,12 @@ class TestDirective(Directive): _("missing '+' or '-' in '%s' option.") % option, line=self.lineno) continue - if option_name not in doctest.OPTIONFLAGS_BY_NAME: # type: ignore + if option_name not in doctest.OPTIONFLAGS_BY_NAME: self.state.document.reporter.warning( _("'%s' is not a valid option.") % option_name, line=self.lineno) continue - flag = doctest.OPTIONFLAGS_BY_NAME[option[1:]] # type: ignore + flag = doctest.OPTIONFLAGS_BY_NAME[option[1:]] node['options'][flag] = (option[0] == '+') if self.name == 'doctest' and 'pyversion' in self.options: try: @@ -148,7 +148,7 @@ class TestDirective(Directive): operand, option_version = [item.strip() for item in option.split()] running_version = platform.python_version() if not compare_version(running_version, option_version, operand): - flag = doctest.OPTIONFLAGS_BY_NAME['SKIP'] # type: ignore + flag = doctest.OPTIONFLAGS_BY_NAME['SKIP'] node['options'][flag] = True # Skip the test except ValueError: self.state.document.reporter.warning( @@ -188,7 +188,7 @@ class TestoutputDirective(TestDirective): } -parser = doctest.DocTestParser() # type: ignore +parser = doctest.DocTestParser() # helper classes @@ -240,14 +240,14 @@ class TestCode(object): self.code, self.type, self.lineno, self.options) -class SphinxDocTestRunner(doctest.DocTestRunner): # type: ignore - def summarize(self, out, verbose=None): +class SphinxDocTestRunner(doctest.DocTestRunner): + def summarize(self, out, verbose=None): # type: ignore # type: (Callable, bool) -> Tuple[int, int] string_io = StringIO() old_stdout = sys.stdout sys.stdout = string_io try: - res = doctest.DocTestRunner.summarize(self, verbose) # type: ignore + res = doctest.DocTestRunner.summarize(self, verbose) finally: sys.stdout = old_stdout out(string_io.getvalue()) @@ -257,7 +257,7 @@ class SphinxDocTestRunner(doctest.DocTestRunner): # type: ignore module_globals=None): # type: (unicode, Any) -> Any # this is overridden from DocTestRunner adding the try-except below - m = self._DocTestRunner__LINECACHE_FILENAME_RE.match(filename) + m = self._DocTestRunner__LINECACHE_FILENAME_RE.match(filename) # type: ignore if m and m.group('name') == self.test.name: try: example = self.test.examples[int(m.group('examplenum'))] @@ -268,7 +268,7 @@ class SphinxDocTestRunner(doctest.DocTestRunner): # type: ignore pass else: return example.source.splitlines(True) - return self.save_linecache_getlines(filename, module_globals) + return self.save_linecache_getlines(filename, module_globals) # type: ignore # the new builder -- use sphinx-build.py -b doctest to run @@ -379,8 +379,8 @@ Doctest summary self.cleanup_runner = SphinxDocTestRunner(verbose=False, optionflags=self.opt) - self.test_runner._fakeout = self.setup_runner._fakeout - self.cleanup_runner._fakeout = self.setup_runner._fakeout + self.test_runner._fakeout = self.setup_runner._fakeout # type: ignore + self.cleanup_runner._fakeout = self.setup_runner._fakeout # type: ignore if self.config.doctest_test_doctest_blocks: def condition(node): @@ -466,7 +466,7 @@ Doctest summary if not examples: return True # simulate a doctest with the code - sim_doctest = doctest.DocTest(examples, {}, # type: ignore + sim_doctest = doctest.DocTest(examples, {}, '%s (%s code)' % (group.name, what), filename_str, 0, None) sim_doctest.globs = ns @@ -487,7 +487,7 @@ Doctest summary if len(code) == 1: # ordinary doctests (code/output interleaved) try: - test = parser.get_doctest( + test = parser.get_doctest( # type: ignore doctest_encode(code[0].code, self.env.config.source_encoding), {}, # type: ignore # NOQA group.name, filename_str, code[0].lineno) except Exception: @@ -507,9 +507,9 @@ Doctest summary output = code[1] and code[1].code or '' options = code[1] and code[1].options or {} # disable processing as it is not needed - options[doctest.DONT_ACCEPT_BLANKLINE] = True # type: ignore + options[doctest.DONT_ACCEPT_BLANKLINE] = True # find out if we're testing an exception - m = parser._EXCEPTION_RE.match(output) + m = parser._EXCEPTION_RE.match(output) # type: ignore if m: exc_msg = m.group('msg') else: @@ -546,6 +546,6 @@ def setup(app): app.add_config_value('doctest_global_cleanup', '', False) app.add_config_value( 'doctest_default_flags', - doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL, # type: ignore # NOQA + doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL, False) return {'version': sphinx.__display_version__, 'parallel_read_safe': True} diff --git a/sphinx/roles.py b/sphinx/roles.py index 7b5880873..dbd136fdb 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -69,7 +69,7 @@ class XRefRole(object): * Subclassing and overwriting `process_link()` and/or `result_nodes()`. """ - nodeclass = addnodes.pending_xref + nodeclass = addnodes.pending_xref # type: Type[nodes.Node] innernodeclass = nodes.literal def __init__(self, fix_parens=False, lowercase=False, diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index bfb4628dd..4ec2ee94a 100644 --- a/sphinx/testing/util.py +++ b/sphinx/testing/util.py @@ -337,7 +337,7 @@ class _DeprecationWrapper(object): return getattr(self._mod, attr) -sys.modules[__name__] = _DeprecationWrapper(sys.modules[__name__], dict( # type: ignore +sys.modules[__name__] = _DeprecationWrapper(sys.modules[__name__], dict( with_app=(pytest.mark.sphinx, 'pytest.mark.sphinx'), TestApp=(SphinxTestApp, 'SphinxTestApp'), gen_with_app=(gen_with_app, 'pytest.mark.parametrize'),