2323NESTED_FULL = 'full'
2424NESTED_SHORT = 'short'
2525NESTED_NONE = 'none'
26+ NestedT = ty .Literal ['full' , 'short' , 'none' , None ]
2627
2728ANSI_ESC_SEQ_RE = re .compile (r'\x1B\[\d+(;\d+){0,2}m' , flags = re .MULTILINE )
2829
@@ -315,7 +316,7 @@ def _filter_commands(
315316
316317def _format_command (
317318 ctx : click .Context ,
318- nested : str ,
319+ nested : NestedT ,
319320 commands : ty .Optional [ty .List [str ]] = None ,
320321) -> ty .Generator [str , None , None ]:
321322 """Format the output of `click.Command`."""
@@ -391,16 +392,16 @@ def _format_command(
391392 yield ''
392393
393394
394- def nested (argument : ty .Optional [str ]) -> ty . Optional [ str ] :
395+ def nested (argument : ty .Optional [str ]) -> NestedT :
395396 values = (NESTED_FULL , NESTED_SHORT , NESTED_NONE , None )
396397
397398 if argument not in values :
398399 raise ValueError (
399400 "%s is not a valid value for ':nested:'; allowed values: %s"
400- % directives .format_values (values )
401+ % directives .format_values (values ) # type: ignore
401402 )
402403
403- return argument
404+ return ty . cast ( NestedT , argument )
404405
405406
406407class ClickDirective (rst .Directive ):
@@ -456,7 +457,7 @@ def _generate_nodes(
456457 name : str ,
457458 command : click .Command ,
458459 parent : ty .Optional [click .Context ],
459- nested : str ,
460+ nested : NestedT ,
460461 commands : ty .Optional [ty .List [str ]] = None ,
461462 semantic_group : bool = False ,
462463 ) -> ty .List [nodes .section ]:
@@ -490,7 +491,7 @@ def _generate_nodes(
490491
491492 # Summary
492493 source_name = ctx .command_path
493- result = statemachine .ViewList ()
494+ result = statemachine .StringList ()
494495
495496 ctx .meta ["sphinx-click-env" ] = self .env
496497 if semantic_group :
@@ -530,15 +531,15 @@ def _generate_nodes(
530531
531532 return [section ]
532533
533- def run (self ) -> ty .Iterable [nodes .section ]:
534+ def run (self ) -> ty .Sequence [nodes .section ]:
534535 self .env = self .state .document .settings .env
535536
536537 command = self ._load_module (self .arguments [0 ])
537538
538539 if 'prog' not in self .options :
539540 raise self .error (':prog: must be specified' )
540541
541- prog_name = self .options . get ( 'prog' )
542+ prog_name = self .options [ 'prog' ]
542543 show_nested = 'show-nested' in self .options
543544 nested = self .options .get ('nested' )
544545
@@ -557,7 +558,7 @@ def run(self) -> ty.Iterable[nodes.section]:
557558 commands = None
558559 if self .options .get ('commands' ):
559560 commands = [
560- command .strip () for command in self .options . get ( 'commands' ) .split (',' )
561+ command .strip () for command in self .options [ 'commands' ] .split (',' )
561562 ]
562563
563564 return self ._generate_nodes (prog_name , command , None , nested , commands )
0 commit comments