more_autodoc.typevars

Documenter for module level typing.TypeVar's, similar to Sphinx’s autotypevar but with a different appearance.

New in version 1.3.0.

Enable sphinx_toolbox.more_autodoc.typevars by adding the following to the extensions variable in your conf.py:

extensions = [
    ...
    'sphinx_toolbox.more_autodoc.typevars',
    ]

For more information see https://www.sphinx-doc.org/en/master/usage/extensions#third-party-extensions .

Configuration

all_typevars
Type: bool
Default: False

Document all typing.TypeVars, even if they have no docstring.

no_unbound_typevars
Type: bool
Default: True

Only document typing.TypeVars that have a constraint of are bound.

This option has no effect if all_typevars is False.

Usage

.. autotypevar::

Directive to automatically document a typing.TypeVar.

The output is based on the autodata directive, and takes all of its options plus these additional ones:

:no-value:

Don’t show the value of the variable.

:value: value (string)

Show this instead of the value taken from the Python source code.

:no-type:

Don’t show the type of the variable.

API Reference

Classes:

TypeVarDocumenter(directive, name[, indent])

Alternative version of sphinx.ext.autodoc.TypeVarDocumenter with better type hint rendering.

Functions:

unskip_typevars(app, what, name, obj, skip, …)

Unskip undocumented typing.TypeVars if all_typevars is True.

setup(app)

Setup sphinx_toolbox.more_autodoc.typevars.

class TypeVarDocumenter(directive, name, indent='')[source]

Bases: VariableDocumenter

Alternative version of sphinx.ext.autodoc.TypeVarDocumenter with better type hint rendering.

Specialized Documenter subclass for typing.TypeVars.

Methods:

can_document_member(member, membername, …)

Called to see if a member can be documented by this documenter.

resolve_type(forward_ref)

Resolve a typing.ForwardRef using the module the TypeVar belongs to.

add_content(more_content[, no_docstring])

Add content from docstrings, attribute documentation and user.

add_directive_header(sig)

Add the directive’s header.

get_doc([encoding, ignore])

Decode and return lines of the docstring(s) for the object.

classmethod can_document_member(member, membername, isattr, parent)[source]

Called to see if a member can be documented by this documenter.

Parameters
  • member (Any) – The member being checked.

  • membername (str) – The name of the member.

  • isattr (bool)

  • parent (Any) – The parent of the member.

Return type

bool

resolve_type(forward_ref)[source]

Resolve a typing.ForwardRef using the module the TypeVar belongs to.

Parameters

forward_ref (ForwardRef)

Return type

Type

add_content(more_content, no_docstring=False)[source]

Add content from docstrings, attribute documentation and user.

Parameters
add_directive_header(sig)[source]

Add the directive’s header.

Parameters

sig (str)

get_doc(encoding=None, ignore=None)[source]

Decode and return lines of the docstring(s) for the object.

Parameters
Return type

List[List[str]]

unskip_typevars(app, what, name, obj, skip, options)[source]

Unskip undocumented typing.TypeVars if all_typevars is True.

Parameters
  • app (Sphinx) – The Sphinx application.

  • what (str) – The type of the object which the docstring belongs to (one of 'module', 'class', 'exception', 'function', 'method', 'attribute').

  • name (str) – The fully qualified name of the object.

  • obj (Any) – The object itself.

  • skip (bool) – A boolean indicating if autodoc will skip this member if the user handler does not override the decision.

  • options (Dict[str, Any]) – The options given to the directive: an object with attributes inherited_members, undoc_members, show_inheritance and noindex that are true if the flag option of same name was given to the auto directive.

Return type

Optional[bool]

setup(app)[source]

Setup sphinx_toolbox.more_autodoc.typevars.

Parameters

app (Sphinx) – The Sphinx application.

Return type

SphinxExtMetadata