11
11
The autosummary directive has the form::
12
12
13
13
.. autosummary::
14
- :no- signatures:
14
+ :signatures: none
15
15
:toctree: generated/
16
16
17
17
module.function_1
@@ -237,19 +237,13 @@ class Autosummary(SphinxDirective):
237
237
'caption' : directives .unchanged_required ,
238
238
'class' : directives .class_option ,
239
239
'toctree' : directives .unchanged ,
240
- 'no-signatures ' : directives .flag ,
240
+ 'nosignatures ' : directives .flag ,
241
241
'recursive' : directives .flag ,
242
+ 'signatures' : directives .unchanged ,
242
243
'template' : directives .unchanged ,
243
- 'nosignatures' : directives .flag ,
244
244
}
245
245
246
246
def run (self ) -> list [Node ]:
247
- # Copy the old option name to the new one
248
- # xref RemovedInSphinx90Warning
249
- # deprecate nosignatures in Sphinx 9.0
250
- if 'no-signatures' not in self .options and 'nosignatures' in self .options :
251
- self .options ['no-signatures' ] = self .options ['nosignatures' ]
252
-
253
247
self .bridge = DocumenterBridge (
254
248
self .env , self .state .document .reporter , Options (), self .lineno , self .state
255
249
)
@@ -336,13 +330,25 @@ def create_documenter(
336
330
doccls = get_documenter (app , obj , parent )
337
331
return doccls (self .bridge , full_name )
338
332
339
- def get_items (self , names : list [str ]) -> list [tuple [str , str , str , str ]]:
333
+ def get_items (self , names : list [str ]) -> list [tuple [str , str | None , str , str ]]:
340
334
"""Try to import the given names, and return a list of
341
335
``[(name, signature, summary_string, real_name), ...]``.
336
+
337
+ signature is already formatted and is None if :nosignatures: option was given.
342
338
"""
343
339
prefixes = get_import_prefixes_from_env (self .env )
344
340
345
- items : list [tuple [str , str , str , str ]] = []
341
+ items : list [tuple [str , str | None , str , str ]] = []
342
+
343
+ signatures_option = self .options .get ('signatures' )
344
+ if signatures_option is None :
345
+ signatures_option = 'none' if 'nosignatures' in self .options else 'long'
346
+ if signatures_option not in {'none' , 'short' , 'long' }:
347
+ msg = (
348
+ 'Invalid value for autosummary :signatures: option: '
349
+ f"{ signatures_option !r} . Valid values are 'none', 'short', 'long'"
350
+ )
351
+ raise ValueError (msg )
346
352
347
353
max_item_chars = 50
348
354
@@ -407,17 +413,22 @@ def get_items(self, names: list[str]) -> list[tuple[str, str, str, str]]:
407
413
408
414
# -- Grab the signature
409
415
410
- try :
411
- sig = documenter .format_signature (show_annotation = False )
412
- except TypeError :
413
- # the documenter does not support ``show_annotation`` option
414
- sig = documenter .format_signature ()
415
-
416
- if not sig :
417
- sig = ''
416
+ if signatures_option == 'none' :
417
+ sig = None
418
418
else :
419
- max_chars = max (10 , max_item_chars - len (display_name ))
420
- sig = mangle_signature (sig , max_chars = max_chars )
419
+ try :
420
+ sig = documenter .format_signature (show_annotation = False )
421
+ except TypeError :
422
+ # the documenter does not support ``show_annotation`` option
423
+ sig = documenter .format_signature ()
424
+ if not sig :
425
+ sig = ''
426
+ elif signatures_option == 'short' :
427
+ if sig != '()' :
428
+ sig = '(…)'
429
+ else : # signatures_option == 'long'
430
+ max_chars = max (10 , max_item_chars - len (display_name ))
431
+ sig = mangle_signature (sig , max_chars = max_chars )
421
432
422
433
# -- Grab the summary
423
434
@@ -431,7 +442,7 @@ def get_items(self, names: list[str]) -> list[tuple[str, str, str, str]]:
431
442
432
443
return items
433
444
434
- def get_table (self , items : list [tuple [str , str , str , str ]]) -> list [Node ]:
445
+ def get_table (self , items : list [tuple [str , str | None , str , str ]]) -> list [Node ]:
435
446
"""Generate a proper list of table nodes for autosummary:: directive.
436
447
437
448
*items* is a list produced by :meth:`get_items`.
@@ -469,10 +480,11 @@ def append_row(*column_texts: str) -> None:
469
480
470
481
for name , sig , summary , real_name in items :
471
482
qualifier = 'obj'
472
- if 'no-signatures' not in self .options :
473
- col1 = f':py:{ qualifier } :`{ name } <{ real_name } >`\\ { rst .escape (sig )} '
474
- else :
483
+ if sig is None :
475
484
col1 = f':py:{ qualifier } :`{ name } <{ real_name } >`'
485
+ else :
486
+ col1 = f':py:{ qualifier } :`{ name } <{ real_name } >`\\ { rst .escape (sig )} '
487
+
476
488
col2 = summary
477
489
append_row (col1 , col2 )
478
490
0 commit comments