diff options
Diffstat (limited to 'sphinx/ext/autodoc/directive.py')
-rw-r--r-- | sphinx/ext/autodoc/directive.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index 3a3434fc8..57ba12017 100644 --- a/sphinx/ext/autodoc/directive.py +++ b/sphinx/ext/autodoc/directive.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.ext.autodoc.directive ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -8,7 +7,7 @@ """ from docutils import nodes -from docutils.statemachine import ViewList +from docutils.statemachine import StringList from docutils.utils import assemble_option_dict from sphinx.ext.autodoc import Options, get_documenters @@ -18,8 +17,9 @@ from sphinx.util.nodes import nested_parse_with_titles if False: # For type annotation - from typing import Any, Dict, List, Set, Type # NOQA - from docutils.statemachine import State, StateMachine, StringList # NOQA + from typing import Any, Callable, Dict, List, Set, Type # NOQA + from docutils.parsers.rst.state import RSTState # NOQA + from docutils.statemachine import StateMachine, StringList # NOQA from docutils.utils import Reporter # NOQA from sphinx.config import Config # NOQA from sphinx.environment import BuildEnvironment # NOQA @@ -31,18 +31,23 @@ logger = logging.getLogger(__name__) # common option names for autodoc directives AUTODOC_DEFAULT_OPTIONS = ['members', 'undoc-members', 'inherited-members', 'show-inheritance', 'private-members', 'special-members', - 'ignore-module-all', 'exclude-members'] + 'ignore-module-all', 'exclude-members', 'member-order'] -class DummyOptionSpec(object): +class DummyOptionSpec(dict): """An option_spec allows any options.""" + def __bool__(self): + # type: () -> bool + """Behaves like some options are defined.""" + return True + def __getitem__(self, key): - # type: (Any) -> Any + # type: (str) -> Callable[[str], str] return lambda x: x -class DocumenterBridge(object): +class DocumenterBridge: """A parameters container for Documenters.""" def __init__(self, env, reporter, options, lineno): @@ -51,11 +56,11 @@ class DocumenterBridge(object): self.reporter = reporter self.genopt = options self.lineno = lineno - self.filename_set = set() # type: Set[unicode] - self.result = ViewList() + self.filename_set = set() # type: Set[str] + self.result = StringList() def warn(self, msg): - # type: (unicode) -> None + # type: (str) -> None logger.warning(msg, location=(self.env.docname, self.lineno)) @@ -74,11 +79,11 @@ def process_documenter_options(documenter, config, options): def parse_generated_content(state, content, documenter): - # type: (State, StringList, Documenter) -> List[nodes.Node] + # type: (RSTState, StringList, Documenter) -> List[nodes.Node] """Parse a generated content by Documenter.""" with switch_source_input(state, content): if documenter.titles_allowed: - node = nodes.section() + node = nodes.section() # type: nodes.Element # necessary so that the child nodes get the right source/line set node.document = state.document nested_parse_with_titles(state, content, node) @@ -107,7 +112,7 @@ class AutodocDirective(SphinxDirective): reporter = self.state.document.reporter try: - source, lineno = reporter.get_source_and_line(self.lineno) + source, lineno = reporter.get_source_and_line(self.lineno) # type: ignore except AttributeError: source, lineno = (None, None) logger.debug('[autodoc] %s:%s: input:\n%s', source, lineno, self.block_text) |