Skip to content

Commit 73bb50d

Browse files
committed
Add :signatures: option to autosummary directive
This is in preparation of extending singature formating.
1 parent ec201c2 commit 73bb50d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

doc/usage/extensions/autosummary.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,22 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
8989
9090
.. versionadded:: 3.1
9191
92+
.. rst:directive:option:: signatures: format
93+
94+
How to display signatures. Valid values are
95+
96+
- ``long`` (*default*): use a long signature. This is still cut off so that name
97+
plus signature do not exceeed a certain length.
98+
- ``none``: do not show signatures.
99+
100+
.. versionadded:: 9.0
101+
92102
.. rst:directive:option:: nosignatures
93103
94104
Do not show function signatures in the summary.
95105
106+
This is equivalent to ``:signatures: none``.
107+
96108
.. versionadded:: 0.6
97109
98110
.. rst:directive:option:: template: filename

sphinx/ext/autosummary/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class Autosummary(SphinxDirective):
228228
'toctree': directives.unchanged,
229229
'nosignatures': directives.flag,
230230
'recursive': directives.flag,
231+
'signatures': directives.unchanged,
231232
'template': directives.unchanged,
232233
}
233234

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

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

321+
signatures_option = self.options.get('signatures')
322+
if signatures_option is None:
323+
signatures_option = 'none' if self.options.get('nosignatures') else 'long'
324+
if signatures_option not in ['none', 'long']:
325+
raise ValueError(f"Invalid value for autosummary :signatures: option: "
326+
f"{signatures_option!r}. "
327+
f"Valid values are 'none', 'long'")
328+
320329
max_item_chars = 50
321330

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

368377
# -- Grab the signature
369378

370-
if 'nosignatures' in self.options:
379+
if signatures_option == 'none':
371380
sig = None
372381
else:
373382
try:

0 commit comments

Comments
 (0)