diff options
Diffstat (limited to '')
-rw-r--r-- | sphinx/directives/other.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 65cd90b..286db29 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -3,7 +3,7 @@ from __future__ import annotations import re from os.path import abspath, relpath from pathlib import Path -from typing import TYPE_CHECKING, Any, cast +from typing import TYPE_CHECKING, Any, ClassVar, cast from docutils import nodes from docutils.parsers.rst import directives @@ -13,7 +13,7 @@ from docutils.parsers.rst.directives.misc import Include as BaseInclude from docutils.statemachine import StateMachine from sphinx import addnodes -from sphinx.domains.changeset import VersionChange # noqa: F401 # for compatibility +from sphinx.domains.changeset import VersionChange # NoQA: F401 # for compatibility from sphinx.domains.std import StandardDomain from sphinx.locale import _, __ from sphinx.util import docname_join, logging, url_re @@ -22,10 +22,12 @@ from sphinx.util.matching import Matcher, patfilter from sphinx.util.nodes import explicit_title_re if TYPE_CHECKING: + from collections.abc import Sequence + from docutils.nodes import Element, Node from sphinx.application import Sphinx - from sphinx.util.typing import OptionSpec + from sphinx.util.typing import ExtensionMetadata, OptionSpec glob_re = re.compile(r'.*[*?\[].*') @@ -43,6 +45,7 @@ class TocTree(SphinxDirective): Directive to notify Sphinx about the hierarchical structure of the docs, and to include a table-of-contents like tree in the current document. """ + has_content = True required_arguments = 0 optional_arguments = 0 @@ -173,11 +176,12 @@ class Author(SphinxDirective): Directive to give the name of the author of the current document or section. Shown in the output only if the show_authors option is on. """ + has_content = False required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True - option_spec: OptionSpec = {} + option_spec: ClassVar[OptionSpec] = {} def run(self) -> list[Node]: if not self.config.show_authors: @@ -206,6 +210,7 @@ class SeeAlso(BaseAdmonition): """ An admonition mentioning things to look at as reference. """ + node_class = addnodes.seealso @@ -213,11 +218,12 @@ class TabularColumns(SphinxDirective): """ Directive to give an explicit tabulary column definition to LaTeX. """ + has_content = False required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True - option_spec: OptionSpec = {} + option_spec: ClassVar[OptionSpec] = {} def run(self) -> list[Node]: node = addnodes.tabular_col_spec() @@ -230,11 +236,12 @@ class Centered(SphinxDirective): """ Directive to create a centered line of bold text. """ + has_content = False required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True - option_spec: OptionSpec = {} + option_spec: ClassVar[OptionSpec] = {} def run(self) -> list[Node]: if not self.arguments: @@ -252,11 +259,12 @@ class Acks(SphinxDirective): """ Directive for a list of names. """ + has_content = True required_arguments = 0 optional_arguments = 0 final_argument_whitespace = False - option_spec: OptionSpec = {} + option_spec: ClassVar[OptionSpec] = {} def run(self) -> list[Node]: node = addnodes.acks() @@ -274,11 +282,12 @@ class HList(SphinxDirective): """ Directive for a list that gets compacted horizontally. """ + has_content = True required_arguments = 0 optional_arguments = 0 final_argument_whitespace = False - option_spec: OptionSpec = { + option_spec: ClassVar[OptionSpec] = { 'columns': int, } @@ -311,11 +320,12 @@ class Only(SphinxDirective): """ Directive to only include text if the given tag(s) are enabled. """ + has_content = True required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True - option_spec: OptionSpec = {} + option_spec: ClassVar[OptionSpec] = {} def run(self) -> list[Node]: node = addnodes.only() @@ -371,14 +381,14 @@ class Include(BaseInclude, SphinxDirective): "correctly", i.e. relative to source directory. """ - def run(self) -> list[Node]: + def run(self) -> Sequence[Node]: # To properly emit "include-read" events from included RST text, # we must patch the ``StateMachine.insert_input()`` method. # In the future, docutils will hopefully offer a way for Sphinx # to provide the RST parser to use # when parsing RST text that comes in via Include directive. - def _insert_input(include_lines, source): + def _insert_input(include_lines: list[str], source: str) -> None: # First, we need to combine the lines back into text so that # we can send it with the include-read event. # In docutils 0.18 and later, there are two lines at the end @@ -405,7 +415,7 @@ class Include(BaseInclude, SphinxDirective): # Only enable this patch if there are listeners for 'include-read'. if self.env.app.events.listeners.get('include-read'): # See https://github.com/python/mypy/issues/2427 for details on the mypy issue - self.state_machine.insert_input = _insert_input # type: ignore[method-assign] + self.state_machine.insert_input = _insert_input if self.arguments[0].startswith('<') and \ self.arguments[0].endswith('>'): @@ -417,7 +427,7 @@ class Include(BaseInclude, SphinxDirective): return super().run() -def setup(app: Sphinx) -> dict[str, Any]: +def setup(app: Sphinx) -> ExtensionMetadata: directives.register_directive('toctree', TocTree) directives.register_directive('sectionauthor', Author) directives.register_directive('moduleauthor', Author) |