mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Update type annotations in sphinx.ext.*
This commit is contained in:
parent
81964e036b
commit
79b3aca406
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user