autodoc2.sphinx.docstring

Directive for rendering docstrings.

Module Contents

Classes

DocstringRenderer

Directive to render a docstring of an object.

Functions

parser_options

Return a docutils parser whose name matches the argument. (Directive option conversion function.)

summary_option

Must be empty or a positive integer.

parsing_context

Restore the parsing context after a nested parse with a different parser.

change_source

Temporarily change the source and line number.

_example

This is an example docstring, written in MyST.

API

autodoc2.sphinx.docstring.parser_options(argument: str) docutils.parsers.Parser | None[source]

Return a docutils parser whose name matches the argument. (Directive option conversion function.)

Return None, if the argument evaluates to False. Raise ValueError if importing the parser module fails.

autodoc2.sphinx.docstring.summary_option(argument: str) int | None[source]

Must be empty or a positive integer.

class autodoc2.sphinx.docstring.DocstringRenderer(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]

Bases: sphinx.util.docutils.SphinxDirective

Directive to render a docstring of an object.

Initialization

has_content = False
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec: ClassVar[dict[str, Any]] = None
run() list[docutils.nodes.Node][source]

Run the directive {a}`1`.

autodoc2.sphinx.docstring.parsing_context() Generator[None, None, None][source]

Restore the parsing context after a nested parse with a different parser.

autodoc2.sphinx.docstring.change_source(state: docutils.parsers.rst.states.RSTStateMachine, source_path: str, line_offset: int) Generator[None, None, None][source]

Temporarily change the source and line number.

autodoc2.sphinx.docstring._example(a: int, b: str) None[source]

This is an example docstring, written in MyST.

It has a code fence:

a = "hallo"

and a table:

a

b

c

1

2

3

and, using the fieldlist extension, a field list:

Parameters:
  • a – the first parameter

  • b – the second parameter

Returns:

the return value