Skip to content

Commit

Permalink
Add :signatures: option to autosummary directive
Browse files Browse the repository at this point in the history
This is in preparation of extending singature formating.
  • Loading branch information
timhoffm committed Dec 6, 2024
1 parent ec201c2 commit 73bb50d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions doc/usage/extensions/autosummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,22 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
.. versionadded:: 3.1
.. rst:directive:option:: signatures: format
How to display signatures. Valid values are
- ``long`` (*default*): use a long signature. This is still cut off so that name
plus signature do not exceeed a certain length.
- ``none``: do not show signatures.
.. versionadded:: 9.0
.. rst:directive:option:: nosignatures
Do not show function signatures in the summary.
This is equivalent to ``:signatures: none``.
.. versionadded:: 0.6
.. rst:directive:option:: template: filename
Expand Down
11 changes: 10 additions & 1 deletion sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class Autosummary(SphinxDirective):
'toctree': directives.unchanged,
'nosignatures': directives.flag,
'recursive': directives.flag,
'signatures': directives.unchanged,
'template': directives.unchanged,
}

Expand Down Expand Up @@ -317,6 +318,14 @@ def get_items(self, names: list[str]) -> list[tuple[str, str | None, str, str]]:

items: list[tuple[str, str | None, str, str]] = []

signatures_option = self.options.get('signatures')
if signatures_option is None:
signatures_option = 'none' if self.options.get('nosignatures') else 'long'
if signatures_option not in ['none', 'long']:
raise ValueError(f"Invalid value for autosummary :signatures: option: "
f"{signatures_option!r}. "
f"Valid values are 'none', 'long'")

max_item_chars = 50

for name in names:
Expand Down Expand Up @@ -367,7 +376,7 @@ def get_items(self, names: list[str]) -> list[tuple[str, str | None, str, str]]:

# -- Grab the signature

if 'nosignatures' in self.options:
if signatures_option == 'none':
sig = None
else:
try:
Expand Down

0 comments on commit 73bb50d

Please sign in to comment.