From abc4b412209058a6658b3f62a82da13482330e5d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 30 Nov 2018 00:03:13 +0900 Subject: [PATCH] Fix annotations for minor methods and functions --- sphinx/environment/__init__.py | 8 ++++---- sphinx/environment/adapters/toctree.py | 2 +- sphinx/environment/collectors/toctree.py | 2 +- sphinx/ext/autodoc/directive.py | 4 ++-- sphinx/ext/autosummary/__init__.py | 8 ++++---- sphinx/ext/doctest.py | 4 ++-- sphinx/ext/extlinks.py | 2 +- sphinx/ext/graphviz.py | 6 +++--- sphinx/ext/ifconfig.py | 4 ++-- sphinx/ext/inheritance_diagram.py | 4 ++-- sphinx/ext/todo.py | 4 ++-- sphinx/roles.py | 2 +- sphinx/util/docfields.py | 6 +++--- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 440160d36f..2fa8b09ea6 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -141,9 +141,9 @@ class BuildEnvironment: # docname -> dict of metadata items # TOC inventory - self.titles = {} # type: Dict[unicode, nodes.Node] + self.titles = {} # type: Dict[unicode, nodes.title] # docname -> title node - self.longtitles = {} # type: Dict[unicode, nodes.Node] + self.longtitles = {} # type: Dict[unicode, nodes.title] # docname -> title node; only different if # set differently with title directive self.tocs = {} # type: Dict[unicode, nodes.Node] @@ -544,7 +544,7 @@ class BuildEnvironment: # --------- RESOLVING REFERENCES AND TOCTREES ------------------------------ def get_doctree(self, docname): - # type: (unicode) -> nodes.Node + # type: (unicode) -> nodes.document """Read the doctree for a file from the pickle and return it.""" filename = path.join(self.doctreedir, docname + '.doctree') with open(filename, 'rb') as f: @@ -555,7 +555,7 @@ class BuildEnvironment: def get_and_resolve_doctree(self, docname, builder, doctree=None, prune_toctrees=True, includehidden=False): - # type: (unicode, Builder, nodes.Node, bool, bool) -> nodes.Node + # type: (unicode, Builder, nodes.Node, bool, bool) -> nodes.document """Read the doctree from the pickle, resolve cross-references and toctrees and return it. """ diff --git a/sphinx/environment/adapters/toctree.py b/sphinx/environment/adapters/toctree.py index 18d95732d0..303d3d28e3 100644 --- a/sphinx/environment/adapters/toctree.py +++ b/sphinx/environment/adapters/toctree.py @@ -121,7 +121,7 @@ class TocTree: # type: (addnodes.toctree, List[nodes.Node], bool, bool) -> List[nodes.Node] """Return TOC entries for a toctree node.""" refs = [(e[0], e[1]) for e in toctreenode['entries']] - entries = [] # type: List[nodes.Node] + entries = [] for (title, ref) in refs: try: refdoc = None diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py index 5c2ef483c6..f848d57811 100644 --- a/sphinx/environment/collectors/toctree.py +++ b/sphinx/environment/collectors/toctree.py @@ -225,7 +225,7 @@ class TocTreeCollector(EnvironmentCollector): fignum_counter = {} # type: Dict[unicode, Dict[Tuple[int, ...], int]] def get_figtype(node): - # type: (nodes.Node) -> unicode + # type: (nodes.Element) -> unicode for domain in env.domains.values(): figtype = domain.get_enumerable_node_type(node) if figtype: diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index 1f773b6e99..344f7c4cdf 100644 --- a/sphinx/ext/autodoc/directive.py +++ b/sphinx/ext/autodoc/directive.py @@ -24,7 +24,7 @@ if False: from sphinx.config import Config # NOQA from sphinx.environment import BuildEnvironment # NOQA from sphinx.ext.autodoc import Documenter # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA logger = logging.getLogger(__name__) @@ -109,7 +109,7 @@ class AutodocDirective(SphinxDirective): final_argument_whitespace = True def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] reporter = self.state.document.reporter try: diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index adcf4e5b29..a9355328ac 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -87,7 +87,7 @@ if False: from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA from sphinx.ext.autodoc import Documenter # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA logger = logging.getLogger(__name__) @@ -235,7 +235,7 @@ class Autosummary(SphinxDirective): msg, line=self.lineno)) def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] self.genopt = Options() self.warnings = [] # type: List[nodes.Node] self.result = ViewList() @@ -613,14 +613,14 @@ def _import_by_name(name): # -- :autolink: (smart default role) ------------------------------------------- def autolink_role(typ, rawtext, etext, lineno, inliner, options={}, content=[]): - # type: (unicode, unicode, unicode, int, Inliner, Dict, List[unicode]) -> Tuple[List[nodes.Node], List[nodes.Node]] # NOQA + # type: (unicode, unicode, unicode, int, Inliner, Dict, List[unicode]) -> Tuple[List[nodes.Node], List[nodes.system_message]] # NOQA """Smart linking role. Expands to ':obj:`text`' if `text` is an object that can be imported; otherwise expands to '*text*'. """ env = inliner.document.settings.env - r = None # type: Tuple[List[nodes.Node], List[nodes.Node]] + r = None # type: Tuple[List[nodes.Node], List[nodes.system_message]] r = env.get_domain('py').role('obj')( 'obj', rawtext, etext, lineno, inliner, options, content) pnode = r[0][0] diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index bdb07b7850..503023de49 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -38,7 +38,7 @@ if False: # For type annotation from typing import Any, Callable, Dict, IO, Iterable, List, Optional, Sequence, Set, Tuple, Type # NOQA from sphinx.application import Sphinx # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA logger = logging.getLogger(__name__) @@ -85,7 +85,7 @@ class TestDirective(SphinxDirective): final_argument_whitespace = True def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] if 'skipif' in self.options: condition = self.options['skipif'] context = {} # type: Dict[str, Any] diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py index ea1c32f3c6..d353e31162 100644 --- a/sphinx/ext/extlinks.py +++ b/sphinx/ext/extlinks.py @@ -41,7 +41,7 @@ if False: def make_link_role(base_url, prefix): # type: (unicode, unicode) -> RoleFunction def role(typ, rawtext, text, lineno, inliner, options={}, content=[]): - # type: (unicode, unicode, unicode, int, Inliner, Dict, List[unicode]) -> Tuple[List[nodes.Node], List[nodes.Node]] # NOQA + # type: (unicode, unicode, unicode, int, Inliner, Dict, List[unicode]) -> Tuple[List[nodes.Node], List[nodes.system_message]] # NOQA text = utils.unescape(text) has_explicit_title, title, part = split_explicit_title(text) try: diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index c2b08bce18..0dad19f989 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -35,7 +35,7 @@ if False: from docutils.parsers.rst import Directive # NOQA from typing import Any, Dict, List, Tuple, Union # NOQA from sphinx.application import Sphinx # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA from sphinx.writers.html import HTMLTranslator # NOQA from sphinx.writers.latex import LaTeXTranslator # NOQA from sphinx.writers.manpage import ManualPageTranslator # NOQA @@ -135,7 +135,7 @@ class Graphviz(SphinxDirective): } def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] if self.arguments: document = self.state.document if self.content: @@ -194,7 +194,7 @@ class GraphvizSimple(SphinxDirective): } def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] node = graphviz() node['code'] = '%s %s {\n%s\n}\n' % \ (self.name, self.arguments[0], '\n'.join(self.content)) diff --git a/sphinx/ext/ifconfig.py b/sphinx/ext/ifconfig.py index 156aaf614c..44f6fc63f9 100644 --- a/sphinx/ext/ifconfig.py +++ b/sphinx/ext/ifconfig.py @@ -30,7 +30,7 @@ if False: # For type annotation from typing import Any, Dict, List # NOQA from sphinx.application import Sphinx # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA class ifconfig(nodes.Element): @@ -46,7 +46,7 @@ class IfConfig(SphinxDirective): option_spec = {} # type: Dict def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] node = ifconfig() node.document = self.state.document set_source_info(self, node) diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index ee262383cf..3806c70a52 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -55,7 +55,7 @@ if False: from typing import Any, Dict, List, Tuple, Dict, Optional # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA from sphinx.writers.html import HTMLTranslator # NOQA from sphinx.writers.latex import LaTeXTranslator # NOQA from sphinx.writers.texinfo import TexinfoTranslator # NOQA @@ -337,7 +337,7 @@ class InheritanceDiagram(SphinxDirective): } def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] node = inheritance_diagram() node.document = self.state.document class_names = self.arguments[0].split() diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py index 8f7cd838ab..1b77c23d48 100644 --- a/sphinx/ext/todo.py +++ b/sphinx/ext/todo.py @@ -31,7 +31,7 @@ if False: from typing import Any, Dict, Iterable, List # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import N_co, unicode # NOQA from sphinx.writers.html import HTMLTranslator # NOQA from sphinx.writers.latex import LaTeXTranslator # NOQA @@ -61,7 +61,7 @@ class Todo(BaseAdmonition, SphinxDirective): } def run(self): - # type: () -> List[nodes.Node] + # type: () -> List[N_co] if not self.options.get('class'): self.options['class'] = ['admonition-todo'] diff --git a/sphinx/roles.py b/sphinx/roles.py index 0c1f74cefa..8b237771c4 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -161,7 +161,7 @@ class XRefRole: return title, ws_re.sub(' ', target) def result_nodes(self, document, env, node, is_ref): - # type: (nodes.document, BuildEnvironment, nodes.Node, bool) -> Tuple[List[nodes.Node], List[nodes.system_message]] # NOQA + # type: (nodes.document, BuildEnvironment, nodes.Element, bool) -> Tuple[List[nodes.Element], List[nodes.system_message]] # NOQA """Called before returning the finished nodes. *node* is the reference node if one was created (*is_ref* is then true), else the content node. This method can add other nodes and must return a ``(nodes, messages)`` diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 92402ce3f6..5d6f037012 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -17,7 +17,7 @@ from sphinx import addnodes if False: # For type annotation - from typing import Any, Dict, List, Tuple # NOQA + from typing import Any, Dict, List, Tuple, Type # NOQA from sphinx.domains import Domain # NOQA from sphinx.environment import BuildEnvironment # NOQA from sphinx.util.typing import unicode # NOQA @@ -67,7 +67,7 @@ class Field: rolename, # type: unicode domain, # type: unicode target, # type: unicode - innernode=addnodes.literal_emphasis, # type: nodes.Node + innernode=addnodes.literal_emphasis, # type: Type[nodes.TextElement] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment ): @@ -85,7 +85,7 @@ class Field: rolename, # type: unicode domain, # type: unicode target, # type: unicode - innernode=addnodes.literal_emphasis, # type: nodes.Node + innernode=addnodes.literal_emphasis, # type: Type[nodes.TextElement] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment ):