summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-16 20:29:35 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-16 20:47:08 +0900
commit79b3aca406c73ef56c80d1867b7ee6ea86b7aee3 (patch)
tree31e6e8338b6c3b4e8d2c2c2c0f7c7672505266cc
parent81964e036b08e182fa9d58c6330a4094083f9070 (diff)
downloadsphinx-git-79b3aca406c73ef56c80d1867b7ee6ea86b7aee3.tar.gz
refactor: Update type annotations in sphinx.ext.*
-rw-r--r--sphinx/ext/autodoc/__init__.py2
-rw-r--r--sphinx/ext/coverage.py2
-rw-r--r--sphinx/ext/duration.py4
-rw-r--r--sphinx/ext/napoleon/docstring.py4
-rw-r--r--sphinx/ext/viewcode.py8
5 files changed, 11 insertions, 9 deletions
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index ae56cb183..22fc42d46 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1065,7 +1065,7 @@ class DecoratorDocumenter(FunctionDocumenter):
# must be lower than FunctionDocumenter
priority = -1
- def format_args(self, **kwargs):
+ def format_args(self, **kwargs: Any) -> Any:
args = super().format_args(**kwargs)
if ',' in args:
return args
diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py
index 987cf2919..e8157848f 100644
--- a/sphinx/ext/coverage.py
+++ b/sphinx/ext/coverage.py
@@ -123,7 +123,7 @@ class CoverageBuilder(Builder):
op.write(' * %-50s [%9s]\n' % (name, typ))
op.write('\n')
- def ignore_pyobj(self, full_name):
+ def ignore_pyobj(self, full_name: str) -> bool:
for exp in self.py_ignorexps:
if exp.search(full_name):
return True
diff --git a/sphinx/ext/duration.py b/sphinx/ext/duration.py
index 02e60cf7e..669baf2f1 100644
--- a/sphinx/ext/duration.py
+++ b/sphinx/ext/duration.py
@@ -11,8 +11,8 @@
from datetime import datetime, timedelta
from itertools import islice
from operator import itemgetter
+from typing import Any, Dict, List
from typing import cast
-from typing import Dict, List
from docutils import nodes
@@ -82,7 +82,7 @@ def on_build_finished(app: Sphinx, error: Exception) -> None:
logger.info('%d.%03d %s', d.seconds, d.microseconds / 1000, docname)
-def setup(app):
+def setup(app: Sphinx) -> Dict[str, Any]:
app.add_domain(DurationDomain)
app.connect('builder-inited', on_builder_inited)
app.connect('source-read', on_source_read)
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index 81f2496cb..7f6ebe478 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -561,7 +561,7 @@ class GoogleDocstring:
lines = self._consume_to_next_section()
self._parsed_lines.extend(lines)
- def _parse_admonition(self, admonition, section):
+ def _parse_admonition(self, admonition: str, section: str) -> List[str]:
# type (str, str) -> List[str]
lines = self._consume_to_next_section()
return self._format_admonition(admonition, lines)
@@ -603,7 +603,7 @@ class GoogleDocstring:
label = labels.get(section.lower(), section)
return self._parse_generic_section(label, use_admonition)
- def _parse_custom_generic_section(self, section):
+ def _parse_custom_generic_section(self, section: str) -> List[str]:
# for now, no admonition for simple custom sections
return self._parse_generic_section(section, False)
diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py
index 09fcd695f..8d035e76a 100644
--- a/sphinx/ext/viewcode.py
+++ b/sphinx/ext/viewcode.py
@@ -54,10 +54,10 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
if app.builder.name.startswith("epub") and not env.config.viewcode_enable_epub:
return
- def has_tag(modname, fullname, docname, refname):
+ def has_tag(modname: str, fullname: str, docname: str, refname: str) -> bool:
entry = env._viewcode_modules.get(modname, None) # type: ignore
if entry is False:
- return
+ return False
code_tags = app.emit_firstresult('viewcode-find-source', modname)
if code_tags is None:
@@ -65,7 +65,7 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
analyzer = ModuleAnalyzer.for_module(modname)
except Exception:
env._viewcode_modules[modname] = False # type: ignore
- return
+ return False
analyzer.find_tags()
code = analyzer.code
@@ -81,6 +81,8 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
used[fullname] = docname
return True
+ return False
+
for objnode in doctree.traverse(addnodes.desc):
if objnode.get('domain') != 'py':
continue