summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc/directive.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/ext/autodoc/directive.py')
-rw-r--r--sphinx/ext/autodoc/directive.py41
1 files changed, 18 insertions, 23 deletions
diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py
index c932c6f9f..c58d0c411 100644
--- a/sphinx/ext/autodoc/directive.py
+++ b/sphinx/ext/autodoc/directive.py
@@ -7,27 +7,22 @@
"""
import warnings
-from typing import Any, Callable, Dict, List, Set
+from typing import Any, Callable, Dict, List, Set, Type
from docutils import nodes
from docutils.nodes import Element, Node
-from docutils.parsers.rst.states import RSTState, Struct
+from docutils.parsers.rst.states import RSTState
from docutils.statemachine import StringList
from docutils.utils import Reporter, assemble_option_dict
from sphinx.config import Config
-from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning
+from sphinx.deprecation import RemovedInSphinx50Warning, RemovedInSphinx60Warning
from sphinx.environment import BuildEnvironment
from sphinx.ext.autodoc import Documenter, Options
from sphinx.util import logging
from sphinx.util.docutils import SphinxDirective, switch_source_input
from sphinx.util.nodes import nested_parse_with_titles
-if False:
- # For type annotation
- from typing import Type # for python3.5.1
-
-
logger = logging.getLogger(__name__)
@@ -56,35 +51,35 @@ class DocumenterBridge:
"""A parameters container for Documenters."""
def __init__(self, env: BuildEnvironment, reporter: Reporter, options: Options,
- lineno: int, state: Any = None) -> None:
+ lineno: int, state: Any) -> None:
self.env = env
self._reporter = reporter
self.genopt = options
self.lineno = lineno
- self.filename_set = set() # type: Set[str]
+ self.record_dependencies: Set[str] = set()
self.result = StringList()
-
- if state:
- self.state = state
- else:
- # create fake object for self.state.document.settings.tab_width
- warnings.warn('DocumenterBridge requires a state object on instantiation.',
- RemovedInSphinx40Warning, stacklevel=2)
- settings = Struct(tab_width=8)
- document = Struct(settings=settings)
- self.state = Struct(document=document)
+ self.state = state
def warn(self, msg: str) -> None:
+ warnings.warn('DocumenterBridge.warn is deprecated. Plase use sphinx.util.logging '
+ 'module instead.',
+ RemovedInSphinx60Warning, stacklevel=2)
logger.warning(msg, location=(self.env.docname, self.lineno))
@property
+ def filename_set(self) -> Set:
+ warnings.warn('DocumenterBridge.filename_set is deprecated.',
+ RemovedInSphinx60Warning, stacklevel=2)
+ return self.record_dependencies
+
+ @property
def reporter(self) -> Reporter:
warnings.warn('DocumenterBridge.reporter is deprecated.',
RemovedInSphinx50Warning, stacklevel=2)
return self._reporter
-def process_documenter_options(documenter: "Type[Documenter]", config: Config, options: Dict
+def process_documenter_options(documenter: Type[Documenter], config: Config, options: Dict
) -> Options:
"""Recognize options of Documenter from user input."""
for name in AUTODOC_DEFAULT_OPTIONS:
@@ -115,7 +110,7 @@ def parse_generated_content(state: RSTState, content: StringList, documenter: Do
"""Parse a generated content by Documenter."""
with switch_source_input(state, content):
if documenter.titles_allowed:
- node = nodes.section() # type: Element
+ node: Element = nodes.section()
# necessary so that the child nodes get the right source/line set
node.document = state.document
nested_parse_with_titles(state, content, node)
@@ -172,7 +167,7 @@ class AutodocDirective(SphinxDirective):
# record all filenames as dependencies -- this will at least
# partially make automatic invalidation possible
- for fn in params.filename_set:
+ for fn in params.record_dependencies:
self.state.document.settings.record_dependencies.add(fn)
result = parse_generated_content(self.state, params.result, documenter)