9. Reference¶
This chapter presents the self-referential documentation of the Sphinx extension by means of the Sphinx extension itself. For state changes, the examples include notes that show the required reST code. Note that state changes require the fully qualified name of the module or class that is pushed to or popped from the state stack.
The code for the following state change is:
.. wtrl_push_current_scope:: core
The code for the following state change is:
.. wtrl_push_current_module:: sphinxcontrib.waterloo_docstrings
9.1. Module extension¶
The code for the following docstring representation is:
.. wtrl_autodoc_module:: extension
Preamble |
normative sections
|
Description |
This module provides the Sphinx integration layer for the Waterloo documentation system. The implementation operates directly on Docutils nodes and defines custom Docutils roles to generate structured documentation output from Waterloo-style docstrings. Sphinx is used as the execution and rendering framework, but the internal data model is based on the Docutils abstract syntax tree (AST). All document structure, including sections, tables, lists, rubrics, and inline markup, is represented using Docutils node classes. The module introduces a configurable To support concise and unambiguous normative documentation, the module maintains explicit scope stacks with the semantics “current module” and “current class”. These scopes define the implicit ownership of subsequently documented functions and methods and are modified using dedicated Docutils roles or directives. The primary goal of this module is correctness, completeness, and reproducibility of normative documentation. Readability and visual presentation are considered secondary and are handled through configurable rendering layers. |
Terminology |
Docutils node An element of the Docutils abstract syntax tree (AST), such as Docutils role An inline markup construct of the form ``:role:`content``` implemented using the Docutils role API. Custom roles provided by this module are registered via Sphinx but conceptually belong to Docutils. Sphinx extension A Python module loaded by Sphinx to extend its parsing, transformation, or rendering behavior. This module is implemented as a Sphinx extension but operates primarily on Docutils data structures. |
Contract |
general
|
Public classes |
|
Class overview |
A class that encapsulates Sphinx and Docutils state, configuration, and rendering logic for Waterloo docstring processing.
Aggregate type for the parameters of role handler functions. |
Public functions |
build_sphinx_nodes, build_sphinx_nodes_full, resolve_qualified_name, wtrl_build_autodoc_module_nodes, wtrl_build_autodoc_function_nodes, wtrl_build_autodoc_class_nodes, wtrl_build_autodoc_class_full_nodes, wtrl_build_push_current_module_nodes, wtrl_build_push_current_class_nodes, wtrl_build_push_current_scope_nodes, wtrl_build_pop_current_module_nodes, wtrl_build_pop_current_class_nodes, wtrl_build_pop_current_scope_nodes, wtrl_build_method_signature_nodes, wtrl_build_function_signature_nodes, wtrl_build_method_signature_block_nodes, wtrl_build_function_signature_block_nodes, wtrl_attr_role, wtrl_class_role, wtrl_cmd_role, wtrl_dfn_role, wtrl_file_role, wtrl_func_role, wtrl_label_role, wtrl_lit_role, wtrl_mod_role, wtrl_norm_role, wtrl_op_role, wtrl_opt_role, wtrl_tag_role, wtrl_type_role, wtrl_value_role, wtrl_var_role, wtrl_var_type_role |
Function overview |
Build a list of Docutils nodes from a docstring tree.
Build a list of Docutils nodes of a class object and its member functions from a docstring tree.
Analyze a qualified name and return the object it refers to plus resolved name components.
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of directive
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role
Implementation of role |
Public types |
Aggregate type for the return value of role handler functions. |
Public constants |
A A A |
Notes |
Last reviewed 2026-07-16 |
| «Module» | sphinxcontrib.waterloo_docstrings.extension |
|---|
The code for the following state change is:
.. wtrl_push_current_module:: sphinxcontrib.waterloo_docstrings.extension
9.1.1. Helper¶
9.1.1.1. Function resolve_qualified_name¶
The code for the following docstring representation is
.. wtrl_autodoc_function:: resolve_qualified_name
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.resolve_qualified_name(
ctx: context | None
qname: str
) -> tuple[object, str, str, list[str]]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
The context which provides current module and current class.
The qualified name to resolve. |
Returns |
Must return a tuple |
Raises |
|
| «Function» | resolve_qualified_name |
|---|
9.1.1.2. Function resolve_markup¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_markup.resolve_markup(
text: str
ctx: context
) -> str
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
The source text containing Waterloo markup patterns to resolve. Markup patterns include naked tokens (Must, may,
The |
Returns |
The input text with all recognized Waterloo markup patterns converted to Sphinx role syntax. Text segments outside markup are escaped for RST special characters. The returned string is ready for parsing by the Sphinx RST parser. |
Raises |
|
See also |
RST_TEXT_ESCAPE_CHARS, RST_ROLE_BODY_ESCAPE_CHARS, WTRL_TOKEN_REPLACEMENTS |
Notes |
Markup_conversion
Escaping Text segments outside markup use Performance Uses compiled regex patterns for efficient token and markup boundary detection. |
| «Function» | resolve_markup |
|---|
9.1.1.3. Function build_sphinx_nodes¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_autodoc.build_sphinx_nodes(
ctx: context
obj: object
doc: mod_docitem.docitem_docstring_base
) -> List[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
Rendering context providing Sphinx state, configuration, inline parsing, and Waterloo role helpers.
The documented Python object.
Parsed Waterloo docstring tree for |
Returns |
List of |
Raises |
|
Notes |
Usage This function is typically not called directly. It is called by the various Scope filtering Scope filtering is handled before the documentation box is built. When placeholders are enabled, skipped objects remain visible in the rendered document as lightweight notes. Linking Internal links are created using anchor ids from Last reviewed 2026-07-23 |
| «Function» | build_sphinx_nodes |
|---|
9.1.1.4. Function build_sphinx_nodes_full¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_autodoc.build_sphinx_nodes_full(
ctx: context
class_obj: Any
session: mod_docitem.DocSession
) -> List[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
Rendering context providing Sphinx state, configuration, diagnostics, inline parsing, and Waterloo role helpers.
The class object to render.
Session object used for parser and validator state shared across the recursive render pass. |
Returns |
List of |
Raises |
|
Notes |
Member errors The current method-rendering branch is intentionally tolerant and may skip problematic methods instead of aborting the complete class rendering pass. Scope filtering Unlike Last reviewed 2026-07-23 |
| «Function» | build_sphinx_nodes_full |
|---|
9.1.1.5. Function parse_inline¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_parse.parse_inline(
inliner: InlinerProtocol
parent: nodes.Element
ln: int
txt: str
) -> List[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
This function wraps inliner.parse() to ensure that any warning or error messages generated during the parsing process are captured and added to the document tree instead of being silently discarded. |
Parameters |
An inline element parser implementing InlinerProtocol. Must have a parse method and a document attribute with settings and reporter attributes.
The parent Element to which parsed content and messages will be appended.
The line number (integer) where the txt input begins in the source document.
The reStructuredText source string (str) to be parsed for inline markup. |
Returns |
List of parsed docutils.nodes.Node instances representing the content found in txt. The returned list is created from the parse output; warning and error messages are appended directly to parent and not returned as part of the list. |
Raises |
|
Notes |
Key difference from direct inliner.parse() calls This function always preserves document messages in the tree. Direct calls to inliner.parse() may discard messages, leading to silent data loss in warnings and error conditions. |
| «Function» | parse_inline |
|---|
9.1.1.6. Class context¶
Preamble |
normative sections
scope
|
Contract |
general
constructor
|
Factory |
|
Public methods |
__init__, set_build_prolog_method_overview, set_build_prolog_method_block, apply_config |
Notes |
Context population Call Last reviewed 2026-07-23 Todo Methods like |
| «Class» | context |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_context.context.__init__(
parse_inline: Callable[[nodes.Element, int, str], List[nodes.Node]]
lineno: int
) -> None
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
A callable that takes a
An integer line number within the source file. |
Returns |
|
Raises |
<empty> |
| «Method» | context.__init__ |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_context.make_context(
app: SphinxAppProtocol | Any
parse_inline: Callable[[nodes.Element, int, str], List[nodes.Node]]
lineno: int
) -> context
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
A Sphinx application object.
A callable that takes a
An integer line number within the source file. |
Returns |
A |
Raises |
<empty> |
Notes |
Last reviewed 2026-07-23 Purpose This factory function provides a convenient way to create a fully initialized rendering context with Sphinx environment and configuration details extracted from the application object. It also searches for and applies optional context configurators, allowing extensible customization of rendering behavior without modifying the context initialization logic directly. Called whenever rendering content into the final document (e.g., HTML) at a specific source location ( |
| «Function» | make_context |
|---|
9.1.2. Directives for docstring rendering¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_autodoc.wtrl_build_autodoc_module_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified module name to build nodes for. |
Returns |
List of generated |
Raises |
|
Notes |
Diagnostics Expected directive failures are rendered into the document instead of being raised as hard Sphinx build errors. Last reviewed 2026-07-23 |
| «Function» | wtrl_build_autodoc_module_nodes |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_autodoc.wtrl_build_autodoc_class_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified class name to document. |
Returns |
List of generated |
Raises |
|
Notes |
Diagnostics Expected directive failures are rendered into the document instead of being raised as hard Sphinx build errors. Last reviewed 2026-07-23 |
| «Function» | wtrl_build_autodoc_class_nodes |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_autodoc.wtrl_build_autodoc_function_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified function name to document. |
Returns |
List of generated |
Raises |
|
Notes |
Diagnostics Expected directive failures are rendered into the document instead of being raised as hard Sphinx build errors. Last reviewed 2026-07-23 |
| «Function» | wtrl_build_autodoc_function_nodes |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_autodoc.wtrl_build_autodoc_class_full_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified name of the class to be documented. |
Returns |
List of generated |
Raises |
|
Notes |
Diagnostics Expected directive failures are rendered into the document instead of being raised as hard Sphinx build errors. Recursion The traversal policy is implemented by Last reviewed 2026-07-23 |
| «Function» | wtrl_build_autodoc_class_full_nodes |
|---|
9.1.3. Directives for controlling the state stack¶
9.1.3.1. Scope stack¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.wtrl_build_push_current_scope_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
scope_tag: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The scope identifier to push onto the stack. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_pop_current_scope_nodes, wtrl_build_push_current_module_nodes, wtrl_build_push_current_class_nodes |
Notes |
Last reviewed 2026-07-16 |
| «Function» | wtrl_build_push_current_scope_nodes |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.wtrl_build_pop_current_scope_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
scope_tag: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The scope identifier to compare and pop from the stack. |
Returns |
The list of generated |
Raises |
|
Notes |
Last reviewed 2026-07-16 |
See also |
wtrl_build_push_current_scope_nodes, wtrl_build_pop_current_module_nodes, wtrl_build_pop_current_class_nodes |
| «Function» | wtrl_build_pop_current_scope_nodes |
|---|
9.1.3.2. Module stack¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.wtrl_build_push_current_module_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified module name to push onto the stack. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_pop_current_module_nodes, wtrl_build_push_current_class_nodes, wtrl_build_push_current_scope_nodes |
Notes |
Last reviewed 2026-07-16 |
| «Function» | wtrl_build_push_current_module_nodes |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.wtrl_build_pop_current_module_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified module name to compare and pop from the stack. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_push_current_module_nodes, wtrl_build_pop_current_class_nodes, wtrl_build_pop_current_scope_nodes |
Notes |
Last reviewed 2026-07-16 |
| «Function» | wtrl_build_pop_current_module_nodes |
|---|
9.1.3.3. Class stack¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.wtrl_build_push_current_class_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified class name to push onto the stack. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_pop_current_class_nodes, wtrl_build_push_current_module_nodes, wtrl_build_push_current_scope_nodes |
Notes |
Last reviewed 2026-07-16 |
| «Function» | wtrl_build_push_current_class_nodes |
|---|
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_state.wtrl_build_pop_current_class_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Description |
Implementation of directive |
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
The qualified class name to compare and pop from the stack. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_push_current_class_nodes, wtrl_build_pop_current_module_nodes, wtrl_build_pop_current_scope_nodes |
Notes |
Last reviewed 2026-07-16 |
| «Function» | wtrl_build_pop_current_class_nodes |
|---|
9.1.4. Directives for rendering signatures¶
9.1.4.1. Function wtrl_build_method_signature_nodes¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_signature.wtrl_build_method_signature_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
Qualified name of method to render. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_function_signature_nodes, wtrl_build_method_signature_block_nodes |
Notes |
Last reviewed 2026-07-23 |
| «Function» | wtrl_build_method_signature_nodes |
|---|
9.1.4.2. Function wtrl_build_function_signature_nodes¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_signature.wtrl_build_function_signature_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
Qualified name of function to render. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_method_signature_nodes, wtrl_build_function_signature_block_nodes |
Notes |
Last reviewed 2026-07-23 |
| «Function» | wtrl_build_function_signature_nodes |
|---|
9.1.4.3. Function wtrl_build_method_signature_block_nodes¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_signature.wtrl_build_method_signature_block_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
Qualified name of method to render. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_method_signature_nodes, wtrl_build_function_signature_block_nodes |
Notes |
Last reviewed 2026-07-23 |
| «Function» | wtrl_build_method_signature_block_nodes |
|---|
9.1.4.4. Function wtrl_build_function_signature_block_nodes¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_signature.wtrl_build_function_signature_block_nodes(
app: SphinxAppProtocol | Any
inliner: InlinerProtocol
lineno: int
qname: str
) -> list[nodes.Node]
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
The Sphinx application instance that carries configuration and environment state.
The Docutils inliner used to parse inline markup into nodes.
Line number in the source document.
Qualified name of function to render. |
Returns |
The list of generated |
Raises |
|
See also |
wtrl_build_method_signature_block_nodes, wtrl_build_function_signature_nodes |
Notes |
Last reviewed 2026-07-23 |
| «Function» | wtrl_build_function_signature_block_nodes |
|---|
9.1.5. Roles for semantic markup¶
9.1.5.1. Helper classes¶
Preamble |
normative sections
scope
|
Contract |
general
constructor
|
| «Class» | RolePara |
|---|
9.1.5.2. Function wtrl_attr_role¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_roles.wtrl_attr_role(
para: RolePara
) -> RoleResult
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
|
Returns |
A |
Raises |
|
See also |
|
Notes |
Representative role This docstring documents the common implementation pattern used by the simple Waterloo roles in this module. Most of these roles create either one Node kind Object-like roles such as Examples
Last reviewed 2026-07-23 |
| «Function» | wtrl_attr_role |
|---|
9.1.5.3. Similar roles¶
There are around 15 more role implementations like wtrl_attr_role.
They differ only in the CSS class passed and in the docutils node
classes literal versus inline. We omit them here
to keep the document low in redundancy.
9.1.5.4. Function wtrl_var_type_role¶
Signature |
sphinxcontrib.waterloo_docstrings.wtrl_roles.wtrl_var_type_role(
para: RolePara
) -> RoleResult
|
Preamble |
normative sections
scope
|
Contract |
general
|
Parameters |
|
Returns |
On valid input, a |
Raises |
|
See also |
|
Notes |
Structure This role is intentionally different from the simple Waterloo roles because it exposes the variable name, separator, and type as separately styleable inline nodes. Separator Only the first colon separates variable and type. Additional colons remain part of the type text. Examples
Last reviewed 2026-07-23 |
| «Function» | wtrl_var_type_role |
|---|
The code for the following state change is:
.. wtrl_pop_current_module:: sphinxcontrib.waterloo_docstrings.extension
The code for the following state change is
.. wtrl_pop_current_module:: sphinxcontrib.waterloo_docstrings
The code for the following state change is
.. wtrl_pop_current_scope:: core