Skip to content

Commit b87c5bc

Browse files
committed
Add ":signatures: short" to autosummary directive
This formats functions and classes with (…) if they have arguments and () if they don't have arguments. This makes it easier to distinguish callables from attributes and properties.
1 parent 73bb50d commit b87c5bc

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

doc/usage/extensions/autosummary.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
9595
9696
- ``long`` (*default*): use a long signature. This is still cut off so that name
9797
plus signature do not exceeed a certain length.
98+
- ``short``: Function and class signatures are displayed as ``(…)`` if they have
99+
arguments and as ``()`` if they don't have arguments.
98100
- ``none``: do not show signatures.
99101
100-
.. versionadded:: 9.0
102+
.. versionadded:: 8.2
101103
102104
.. rst:directive:option:: nosignatures
103105

sphinx/ext/autosummary/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ def get_items(self, names: list[str]) -> list[tuple[str, str | None, str, str]]:
320320

321321
signatures_option = self.options.get('signatures')
322322
if signatures_option is None:
323-
signatures_option = 'none' if self.options.get('nosignatures') else 'long'
324-
if signatures_option not in ['none', 'long']:
323+
signatures_option = 'none' if 'nosignatures' in self.options else 'long'
324+
if signatures_option not in ['none', 'short', 'long']:
325325
raise ValueError(f"Invalid value for autosummary :signatures: option: "
326326
f"{signatures_option!r}. "
327-
f"Valid values are 'none', 'long'")
327+
f"Valid values are 'none', 'short', 'long'")
328328

329329
max_item_chars = 50
330330

@@ -384,10 +384,12 @@ def get_items(self, names: list[str]) -> list[tuple[str, str | None, str, str]]:
384384
except TypeError:
385385
# the documenter does not support ``show_annotation`` option
386386
sig = documenter.format_signature()
387-
388387
if not sig:
389388
sig = ''
390-
else:
389+
elif signatures_option == 'short':
390+
if sig != '()':
391+
sig = '(…)'
392+
else: # signatures_option == 'long'
391393
max_chars = max(10, max_item_chars - len(display_name))
392394
sig = mangle_signature(sig, max_chars=max_chars)
393395

0 commit comments

Comments
 (0)