Merge pull request #5685 from tk0miya/fix_typehints_minor

Fix annotations for minor methods and functions
This commit is contained in:
Takeshi KOMIYA authored and GitHub committed 2018-11-30 00:25:42 +09:00
commit addb5e3230
13 files changed
+28 -28

No files matched your search

+4 -4
View File
@@ -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.
"""
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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:
+2 -2
View File
@@ -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:
+4 -4
View File
@@ -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]
+2 -2
View File
@@ -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]
+1 -1
View File
@@ -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:
+3 -3
View File
@@ -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))
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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()
+2 -2
View File
@@ -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']
+1 -1
View File
@@ -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)``
+3 -3
View File
@@ -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
):