Merge branch 'master' into refactor_docutils_manipulation

This commit is contained in:
Takeshi KOMIYA
2018-12-02 00:42:20 +09:00
committed by GitHub
18 changed files with 109 additions and 99 deletions

View File

@@ -308,6 +308,7 @@ class meta(nodes.Special, nodes.PreBibliographic, nodes.Element):
"""Node for meta directive -- same as docutils' standard meta node,
but pickleable.
"""
rawcontent = None
# inline nodes

View File

@@ -10,6 +10,7 @@
"""
import re
from typing import List, cast
from docutils import nodes
from docutils.parsers.rst import directives, roles
@@ -33,12 +34,12 @@ from sphinx.directives.patches import ( # noqa
if False:
# For type annotation
from typing import Any, Dict, List # NOQA
from typing import Any, Dict # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.config import Config # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.docfields import Field # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
# RE to strip backslash escapes
@@ -118,7 +119,7 @@ class ObjectDescription(SphinxDirective):
pass
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
"""
Main directive entry function, called by docutils upon encountering the
directive.
@@ -200,23 +201,24 @@ class DefaultRole(SphinxDirective):
final_argument_whitespace = False
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
if not self.arguments:
docutils.unregister_role('')
return []
role_name = self.arguments[0]
role, messages = roles.role(role_name, self.state_machine.language,
self.lineno, self.state.reporter)
if role is None:
error = self.state.reporter.error(
'Unknown interpreted text role "%s".' % role_name,
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return messages + [error]
if role:
docutils.register_role('', role)
self.env.temp_data['default_role'] = role_name
else:
literal_block = nodes.literal_block(self.block_text, self.block_text)
reporter = self.state.reporter
error = reporter.error('Unknown interpreted text role "%s".' % role_name,
literal_block, line=self.lineno)
messages += [error]
docutils.register_role('', role)
self.env.temp_data['default_role'] = role_name
return messages
return cast(List[nodes.Node], messages)
class DefaultDomain(SphinxDirective):
@@ -231,7 +233,7 @@ class DefaultDomain(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
domain_name = self.arguments[0].lower()
# if domain_name not in env.domains:
# # try searching by label

View File

@@ -29,7 +29,7 @@ if False:
from typing import Any, Dict, List, Tuple # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.config import Config # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
logger = logging.getLogger(__name__)
@@ -49,7 +49,7 @@ class Highlight(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
linenothreshold = self.options.get('linenothreshold', sys.maxsize)
return [addnodes.highlightlang(lang=self.arguments[0].strip(),
linenothreshold=linenothreshold)]
@@ -59,7 +59,7 @@ class HighlightLang(Highlight):
"""highlightlang directive (deprecated)"""
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
warnings.warn('highlightlang directive is deprecated. '
'Please use highlight directive instead.',
RemovedInSphinx40Warning, stacklevel=2)
@@ -127,7 +127,7 @@ class CodeBlock(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
document = self.state.document
code = u'\n'.join(self.content)
location = self.state_machine.get_source_and_line(self.lineno)
@@ -419,7 +419,7 @@ class LiteralInclude(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
document = self.state.document
if not document.settings.file_insertion_enabled:
return [document.reporter.warning('File insertion disabled',

View File

@@ -28,7 +28,7 @@ if False:
# For type annotation
from typing import Any, Dict, Generator, List, Tuple # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
glob_re = re.compile(r'.*[*?\[].*')
@@ -63,7 +63,7 @@ class TocTree(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
subnode = addnodes.toctree()
subnode['parent'] = self.env.docname
@@ -163,7 +163,7 @@ class Author(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
if not self.config.show_authors:
return []
para = nodes.paragraph(translatable=False) # type: nodes.Element
@@ -178,10 +178,12 @@ class Author(SphinxDirective):
else:
text = _('Author: ')
emph += nodes.Text(text, text)
inodes, messages = self.state.inline_text(self.arguments[0],
self.lineno)
inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
emph.extend(inodes)
return [para] + messages
ret = [para] # type: List[nodes.Node]
ret += messages
return ret
class Index(SphinxDirective):
@@ -195,7 +197,7 @@ class Index(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
arguments = self.arguments[0].split('\n')
targetid = 'index-%s' % self.env.new_serialno('index')
targetnode = nodes.target('', '', ids=[targetid])
@@ -227,7 +229,7 @@ class TabularColumns(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = addnodes.tabular_col_spec()
node['spec'] = self.arguments[0]
set_source_info(self, node)
@@ -245,14 +247,16 @@ class Centered(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
if not self.arguments:
return []
subnode = addnodes.centered() # type: nodes.Element
inodes, messages = self.state.inline_text(self.arguments[0],
self.lineno)
inodes, messages = self.state.inline_text(self.arguments[0], self.lineno)
subnode.extend(inodes)
return [subnode] + messages
ret = [subnode] # type: List[nodes.Node]
ret += messages
return ret
class Acks(SphinxDirective):
@@ -266,14 +270,14 @@ class Acks(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = addnodes.acks()
node.document = self.state.document
self.state.nested_parse(self.content, self.content_offset, node)
if len(node.children) != 1 or not isinstance(node.children[0],
nodes.bullet_list):
return [self.state.document.reporter.warning(
'.. acks content is not a list', line=self.lineno)]
reporter = self.state.document.reporter
return [reporter.warning('.. acks content is not a list', line=self.lineno)]
return [node]
@@ -290,15 +294,15 @@ class HList(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
ncolumns = self.options.get('columns', 2)
node = nodes.paragraph()
node.document = self.state.document
self.state.nested_parse(self.content, self.content_offset, node)
if len(node.children) != 1 or not isinstance(node.children[0],
nodes.bullet_list):
return [self.state.document.reporter.warning(
'.. hlist content is not a list', line=self.lineno)]
reporter = self.state.document.reporter
return [reporter.warning('.. hlist content is not a list', line=self.lineno)]
fulllist = node.children[0]
# create a hlist node where the items are distributed
npercol, nmore = divmod(len(fulllist), ncolumns)
@@ -306,11 +310,10 @@ class HList(SphinxDirective):
newnode = addnodes.hlist()
for column in range(ncolumns):
endindex = index + (column < nmore and (npercol + 1) or npercol)
col = addnodes.hlistcol()
col += nodes.bullet_list()
col[0] += fulllist.children[index:endindex]
bullet_list = nodes.bullet_list()
bullet_list += fulllist.children[index:endindex]
newnode += addnodes.hlistcol('', bullet_list)
index = endindex
newnode += col
return [newnode]
@@ -325,7 +328,7 @@ class Only(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = addnodes.only()
node.document = self.state.document
set_source_info(self, node)
@@ -339,7 +342,7 @@ class Only(SphinxDirective):
self.state.memo.section_level = 0
try:
self.state.nested_parse(self.content, self.content_offset,
node, match_titles=1)
node, match_titles=True)
title_styles = self.state.memo.title_styles
if (not surrounding_title_styles or
not title_styles or
@@ -379,7 +382,7 @@ class Include(BaseInclude, SphinxDirective):
"""
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
if self.arguments[0].startswith('<') and \
self.arguments[0].endswith('>'):
# docutils "standard" includes, do not do path processing

View File

@@ -22,7 +22,7 @@ if False:
# For type annotation
from typing import Dict, List, Tuple # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
class Figure(images.Figure):
@@ -31,9 +31,9 @@ class Figure(images.Figure):
"""
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
name = self.options.pop('name', None)
result = super(Figure, self).run() # type: List[nodes.Node]
result = super(Figure, self).run()
if len(result) == 2 or isinstance(result[0], nodes.system_message):
return result
@@ -54,8 +54,8 @@ class Figure(images.Figure):
class Meta(html.Meta, SphinxDirective):
def run(self):
# type: () -> List[N_co]
result = super(Meta, self).run() # type: List[nodes.Node]
# type: () -> List[nodes.Node]
result = super(Meta, self).run()
for node in result:
if (isinstance(node, nodes.pending) and
isinstance(node.details['nodes'][0], html.MetaBody.meta)):
@@ -124,7 +124,7 @@ class MathDirective(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
latex = '\n'.join(self.content)
if self.arguments and self.arguments[0]:
latex = self.arguments[0] + '\n\n' + latex
@@ -133,14 +133,14 @@ class MathDirective(SphinxDirective):
number=self.options.get('name'),
label=self.options.get('label'),
nowrap='nowrap' in self.options)
ret = [node] # type: List[nodes.Element]
ret = [node] # type: List[nodes.Node]
set_source_info(self, node)
self.add_target(ret)
return ret
def add_target(self, ret):
# type: (List[nodes.Element]) -> None
node = ret[0]
# type: (List[nodes.Node]) -> None
node = cast(nodes.math_block, ret[0])
# assign label automatically if math_number_all enabled
if node['label'] == '' or (self.config.math_number_all and not node['label']):

View File

@@ -25,7 +25,7 @@ if False:
from sphinx.builders import Builder # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.roles import XRefRole # NOQA
from sphinx.util.typing import N_co, RoleFunction, unicode # NOQA
from sphinx.util.typing import RoleFunction, unicode # NOQA
class ObjType:
@@ -243,7 +243,7 @@ class Domain:
class DirectiveAdapter(BaseDirective): # type: ignore
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
self.name = fullname
return super(DirectiveAdapter, self).run()
self._directive_cache[name] = DirectiveAdapter

View File

@@ -27,7 +27,7 @@ if False:
from typing import Any, Dict, List # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
versionlabels = {
@@ -63,7 +63,7 @@ class VersionChange(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = addnodes.versionmodified()
node.document = self.state.document
set_source_info(self, node)
@@ -98,7 +98,10 @@ class VersionChange(SphinxDirective):
domain = cast(ChangeSetDomain, self.env.get_domain('changeset'))
domain.note_changeset(node)
return [node] + messages
ret = [node] # type: List[nodes.Node]
ret += messages
return ret
class ChangeSetDomain(Domain):

View File

@@ -36,7 +36,7 @@ if False:
from sphinx.builders import Builder # NOQA
from sphinx.config import Config # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
logger = logging.getLogger(__name__)
@@ -6472,7 +6472,7 @@ class CPPNamespaceObject(SphinxDirective):
self.state_machine.reporter.warning(msg, line=self.lineno)
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
rootSymbol = self.env.domaindata['cpp']['root_symbol']
if self.arguments[0].strip() in ('NULL', '0', 'nullptr'):
symbol = rootSymbol
@@ -6506,7 +6506,7 @@ class CPPNamespacePushObject(SphinxDirective):
self.state_machine.reporter.warning(msg, line=self.lineno)
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
if self.arguments[0].strip() in ('NULL', '0', 'nullptr'):
return []
parser = DefinitionParser(self.arguments[0], self, self.config)
@@ -6541,7 +6541,7 @@ class CPPNamespacePopObject(SphinxDirective):
self.state_machine.reporter.warning(msg, line=self.lineno)
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
stack = self.env.temp_data.get('cpp:namespace_stack', None)
if not stack or len(stack) == 0:
self.warn("C++ namespace pop on empty stack. Defaulting to gobal scope.")

View File

@@ -29,7 +29,7 @@ if False:
from sphinx.application import Sphinx # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
class JSObject(ObjectDescription):
@@ -250,11 +250,11 @@ class JSModule(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
mod_name = self.arguments[0].strip()
self.env.ref_context['js:module'] = mod_name
noindex = 'noindex' in self.options
ret = []
ret = [] # type: List[nodes.Node]
if not noindex:
self.env.domaindata['js']['modules'][mod_name] = self.env.docname
# Make a duplicate entry in 'objects' to facilitate searching for

View File

@@ -31,7 +31,7 @@ if False:
from sphinx.application import Sphinx # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
logger = logging.getLogger(__name__)
@@ -557,7 +557,7 @@ class PyDecoratorFunction(PyDecoratorMixin, PyModulelevel):
Directive to mark functions meant to be used as decorators.
"""
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
# a decorator function is a function after all
self.name = 'py:function'
return super(PyDecoratorFunction, self).run()
@@ -568,7 +568,7 @@ class PyDecoratorMethod(PyDecoratorMixin, PyClassmember):
Directive to mark methods meant to be used as decorators.
"""
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
self.name = 'py:method'
return super(PyDecoratorMethod, self).run()
@@ -590,11 +590,11 @@ class PyModule(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
modname = self.arguments[0].strip()
noindex = 'noindex' in self.options
self.env.ref_context['py:module'] = modname
ret = []
ret = [] # type: List[nodes.Node]
if not noindex:
self.env.domaindata['py']['modules'][modname] = (self.env.docname,
self.options.get('synopsis', ''),
@@ -629,7 +629,7 @@ class PyCurrentModule(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
modname = self.arguments[0].strip()
if modname == 'None':
self.env.ref_context.pop('py:module', None)

View File

@@ -36,7 +36,7 @@ if False:
from sphinx.application import Sphinx # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, RoleFunction, unicode # NOQA
from sphinx.util.typing import RoleFunction, unicode # NOQA
logger = logging.getLogger(__name__)
@@ -123,7 +123,7 @@ class Target(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
# normalize whitespace in fullname like XRefRole does
fullname = ws_re.sub(' ', self.arguments[0].strip())
targetname = '%s-%s' % (self.name, fullname)
@@ -222,7 +222,7 @@ class Program(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
program = ws_re.sub('-', self.arguments[0].strip())
if program == 'None':
self.env.ref_context.pop('std:program', None)
@@ -290,7 +290,7 @@ class Glossary(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = addnodes.glossary()
node.document = self.state.document
@@ -419,10 +419,9 @@ class ProductionList(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[nodes.Element]
# type: () -> List[nodes.Node]
domain = cast(StandardDomain, self.env.get_domain('std'))
node = addnodes.productionlist() # type: nodes.Element
messages = [] # type: List[nodes.Element]
i = 0
for rule in self.arguments[0].split('\n'):
@@ -444,7 +443,7 @@ class ProductionList(SphinxDirective):
domain.add_object('token', subnode['tokenname'], self.env.docname, idname)
subnode.extend(token_xrefs(tokens))
node.append(subnode)
return [node] + messages
return [node]
class StandardDomain(Domain):

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 N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
logger = logging.getLogger(__name__)
@@ -109,7 +109,7 @@ class AutodocDirective(SphinxDirective):
final_argument_whitespace = True
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
reporter = self.state.document.reporter
try:

View File

@@ -88,7 +88,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 N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
from sphinx.writers.html import HTMLTranslator # NOQA
logger = logging.getLogger(__name__)
@@ -240,7 +240,7 @@ class Autosummary(SphinxDirective):
msg, line=self.lineno))
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
self.genopt = Options()
self.warnings = [] # type: List[nodes.Node]
self.result = ViewList()

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 N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
logger = logging.getLogger(__name__)
@@ -85,7 +85,7 @@ class TestDirective(SphinxDirective):
final_argument_whitespace = True
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
if 'skipif' in self.options:
condition = self.options['skipif']
context = {} # type: Dict[str, Any]

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 N_co, unicode # NOQA
from sphinx.util.typing import 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[N_co]
# type: () -> List[nodes.Node]
if self.arguments:
document = self.state.document
if self.content:
@@ -195,7 +195,7 @@ class GraphvizSimple(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = graphviz()
node['code'] = '%s %s {\n%s\n}\n' % \
(self.name, self.arguments[0], '\n'.join(self.content))
@@ -392,7 +392,7 @@ def render_dot_texinfo(self, node, code, options, prefix='graphviz'):
def texinfo_visit_graphviz(self, node):
# type: (nodes.NodeVisitor, graphviz) -> None
# type: (TexinfoTranslator, graphviz) -> None
render_dot_texinfo(self, node, node['code'], node['options'])

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 N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
class ifconfig(nodes.Element):
@@ -46,13 +46,13 @@ class IfConfig(SphinxDirective):
option_spec = {} # type: Dict
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = ifconfig()
node.document = self.state.document
set_source_info(self, node)
node['expr'] = self.arguments[0]
self.state.nested_parse(self.content, self.content_offset,
node, match_titles=1)
node, match_titles=True)
return [node]

View File

@@ -41,11 +41,13 @@ import inspect
import re
import sys
from hashlib import md5
from typing import Iterable, cast
from docutils import nodes
from docutils.parsers.rst import directives
import sphinx
from sphinx import addnodes
from sphinx.ext.graphviz import (
graphviz, figure_wrapper,
render_dot_html, render_dot_latex, render_dot_texinfo
@@ -55,10 +57,9 @@ from sphinx.util.docutils import SphinxDirective
if False:
# For type annotation
from typing import Any, Dict, List, Tuple, Dict, Optional # NOQA
from sphinx import addnodes # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import unicode # NOQA
from sphinx.writers.html import HTMLTranslator # NOQA
from sphinx.writers.latex import LaTeXTranslator # NOQA
from sphinx.writers.texinfo import TexinfoTranslator # NOQA
@@ -141,7 +142,7 @@ class InheritanceGraph:
"""
def __init__(self, class_names, currmodule, show_builtins=False,
private_bases=False, parts=0, aliases=None, top_classes=[]):
# type: (unicode, str, bool, bool, int, Optional[Dict[unicode, unicode]], List[Any]) -> None # NOQA
# type: (List[unicode], str, bool, bool, int, Optional[Dict[unicode, unicode]], List[Any]) -> None # NOQA
"""*class_names* is a list of child classes to show bases from.
If *show_builtins* is True, then Python builtins will be shown
@@ -156,7 +157,7 @@ class InheritanceGraph:
'inheritance diagram')
def _import_classes(self, class_names, currmodule):
# type: (unicode, str) -> List[Any]
# type: (List[unicode], str) -> List[Any]
"""Import a list of classes."""
classes = [] # type: List[Any]
for name in class_names:
@@ -340,7 +341,7 @@ class InheritanceDiagram(SphinxDirective):
}
def run(self):
# type: () -> List[N_co]
# type: () -> List[nodes.Node]
node = inheritance_diagram()
node.document = self.state.document
class_names = self.arguments[0].split()
@@ -408,7 +409,8 @@ def html_visit_inheritance_diagram(self, node):
graphviz_output_format = self.builder.env.config.graphviz_output_format.upper()
current_filename = self.builder.current_docname + self.builder.out_suffix
urls = {}
for child in node: # type: addnodes.pending_xref
pending_xrefs = cast(Iterable[addnodes.pending_xref], node)
for child in pending_xrefs:
if child.get('refuri') is not None:
if graphviz_output_format == 'SVG':
urls[child['reftitle']] = "../" + child.get('refuri')

View File

@@ -31,7 +31,7 @@ if False:
from typing import Any, Dict, Iterable, List, Tuple # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.environment import BuildEnvironment # NOQA
from sphinx.util.typing import N_co, unicode # NOQA
from sphinx.util.typing import 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[N_co]
# type: () -> List[nodes.Node]
if not self.options.get('class'):
self.options['class'] = ['admonition-todo']