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
|
# must be lower than FunctionDocumenter
|
||||||
priority = -1
|
priority = -1
|
||||||
|
|
||||||
def format_args(self, **kwargs):
|
def format_args(self, **kwargs: Any) -> Any:
|
||||||
args = super().format_args(**kwargs)
|
args = super().format_args(**kwargs)
|
||||||
if ',' in args:
|
if ',' in args:
|
||||||
return args
|
return args
|
||||||
|
@ -123,7 +123,7 @@ class CoverageBuilder(Builder):
|
|||||||
op.write(' * %-50s [%9s]\n' % (name, typ))
|
op.write(' * %-50s [%9s]\n' % (name, typ))
|
||||||
op.write('\n')
|
op.write('\n')
|
||||||
|
|
||||||
def ignore_pyobj(self, full_name):
|
def ignore_pyobj(self, full_name: str) -> bool:
|
||||||
for exp in self.py_ignorexps:
|
for exp in self.py_ignorexps:
|
||||||
if exp.search(full_name):
|
if exp.search(full_name):
|
||||||
return True
|
return True
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from typing import Any, Dict, List
|
||||||
from typing import cast
|
from typing import cast
|
||||||
from typing import Dict, List
|
|
||||||
|
|
||||||
from docutils import nodes
|
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)
|
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.add_domain(DurationDomain)
|
||||||
app.connect('builder-inited', on_builder_inited)
|
app.connect('builder-inited', on_builder_inited)
|
||||||
app.connect('source-read', on_source_read)
|
app.connect('source-read', on_source_read)
|
||||||
|
@ -561,7 +561,7 @@ class GoogleDocstring:
|
|||||||
lines = self._consume_to_next_section()
|
lines = self._consume_to_next_section()
|
||||||
self._parsed_lines.extend(lines)
|
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]
|
# type (str, str) -> List[str]
|
||||||
lines = self._consume_to_next_section()
|
lines = self._consume_to_next_section()
|
||||||
return self._format_admonition(admonition, lines)
|
return self._format_admonition(admonition, lines)
|
||||||
@ -603,7 +603,7 @@ class GoogleDocstring:
|
|||||||
label = labels.get(section.lower(), section)
|
label = labels.get(section.lower(), section)
|
||||||
return self._parse_generic_section(label, use_admonition)
|
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
|
# for now, no admonition for simple custom sections
|
||||||
return self._parse_generic_section(section, False)
|
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:
|
if app.builder.name.startswith("epub") and not env.config.viewcode_enable_epub:
|
||||||
return
|
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
|
entry = env._viewcode_modules.get(modname, None) # type: ignore
|
||||||
if entry is False:
|
if entry is False:
|
||||||
return
|
return False
|
||||||
|
|
||||||
code_tags = app.emit_firstresult('viewcode-find-source', modname)
|
code_tags = app.emit_firstresult('viewcode-find-source', modname)
|
||||||
if code_tags is None:
|
if code_tags is None:
|
||||||
@ -65,7 +65,7 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
|
|||||||
analyzer = ModuleAnalyzer.for_module(modname)
|
analyzer = ModuleAnalyzer.for_module(modname)
|
||||||
except Exception:
|
except Exception:
|
||||||
env._viewcode_modules[modname] = False # type: ignore
|
env._viewcode_modules[modname] = False # type: ignore
|
||||||
return
|
return False
|
||||||
|
|
||||||
analyzer.find_tags()
|
analyzer.find_tags()
|
||||||
code = analyzer.code
|
code = analyzer.code
|
||||||
@ -81,6 +81,8 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
|
|||||||
used[fullname] = docname
|
used[fullname] = docname
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
for objnode in doctree.traverse(addnodes.desc):
|
for objnode in doctree.traverse(addnodes.desc):
|
||||||
if objnode.get('domain') != 'py':
|
if objnode.get('domain') != 'py':
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user