Merge pull request #7209 from tk0miya/refactor_type_annotation2

refactor: Update type annotations in sphinx.*
This commit is contained in:
Takeshi KOMIYA
2020-02-23 20:03:05 +09:00
committed by GitHub
5 changed files with 6 additions and 6 deletions

View File

@@ -36,7 +36,7 @@ nl_escape_re = re.compile(r'\\\n')
strip_backslash_re = re.compile(r'\\(.)')
def optional_int(argument):
def optional_int(argument: str) -> int:
"""
Check for an integer argument or None value; raise ``ValueError`` if not.
"""

View File

@@ -85,14 +85,14 @@ class TocTree(SphinxDirective):
ret.append(wrappernode)
return ret
def parse_content(self, toctree):
def parse_content(self, toctree: addnodes.toctree) -> List[Node]:
suffixes = self.config.source_suffix
# glob target documents
all_docnames = self.env.found_docs.copy()
all_docnames.remove(self.env.docname) # remove current document
ret = []
ret = [] # type: List[Node]
excluded = Matcher(self.config.exclude_patterns)
for entry in self.content:
if not entry:

View File

@@ -197,7 +197,7 @@ def _lazy_translate(catalog: str, namespace: str, message: str) -> str:
return translator.gettext(message)
def get_translation(catalog, namespace='general'):
def get_translation(catalog: str, namespace: str = 'general') -> Callable:
"""Get a translation function based on the *catalog* and *namespace*.
The extension can use this API to translate the messages on the

View File

@@ -356,7 +356,7 @@ class SphinxComponentRegistry:
attrgetter: Callable[[Any, str, Any], Any]) -> None:
self.autodoc_attrgettrs[typ] = attrgetter
def add_css_files(self, filename, **attributes):
def add_css_files(self, filename: str, **attributes: str) -> None:
self.css_files.append((filename, attributes))
def add_js_file(self, filename: str, **attributes: str) -> None:

View File

@@ -131,7 +131,7 @@ class ReferencesResolver(SphinxPostTransform):
if not results:
return None
if len(results) > 1:
def stringify(name, node):
def stringify(name: str, node: Element) -> str:
reftitle = node.get('reftitle', node.astext())
return ':%s:`%s`' % (name, reftitle)
candidates = ' or '.join(stringify(name, role) for name, role in results)