Skip to content

Commit

Permalink
typing: Update for latest types-docutils
Browse files Browse the repository at this point in the history
There's one issue with these stubs - reported at [1] - that we ignore.
Otherwise, this is pretty simple.

[1] python/typeshed#11719

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin committed Apr 5, 2024
1 parent e3970c1 commit 9dcaf75
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NESTED_FULL = 'full'
NESTED_SHORT = 'short'
NESTED_NONE = 'none'
NestedT = ty.Literal['full', 'short', 'none', None]

ANSI_ESC_SEQ_RE = re.compile(r'\x1B\[\d+(;\d+){0,2}m', flags=re.MULTILINE)

Expand Down Expand Up @@ -315,7 +316,7 @@ def _filter_commands(

def _format_command(
ctx: click.Context,
nested: str,
nested: NestedT,
commands: ty.Optional[ty.List[str]] = None,
) -> ty.Generator[str, None, None]:
"""Format the output of `click.Command`."""
Expand Down Expand Up @@ -391,16 +392,16 @@ def _format_command(
yield ''


def nested(argument: ty.Optional[str]) -> ty.Optional[str]:
def nested(argument: ty.Optional[str]) -> NestedT:
values = (NESTED_FULL, NESTED_SHORT, NESTED_NONE, None)

if argument not in values:
raise ValueError(
"%s is not a valid value for ':nested:'; allowed values: %s"
% directives.format_values(values)
% directives.format_values(values) # type: ignore
)

return argument
return ty.cast(NestedT, argument)


class ClickDirective(rst.Directive):
Expand Down Expand Up @@ -456,7 +457,7 @@ def _generate_nodes(
name: str,
command: click.Command,
parent: ty.Optional[click.Context],
nested: str,
nested: NestedT,
commands: ty.Optional[ty.List[str]] = None,
semantic_group: bool = False,
) -> ty.List[nodes.section]:
Expand Down Expand Up @@ -490,7 +491,7 @@ def _generate_nodes(

# Summary
source_name = ctx.command_path
result = statemachine.ViewList()
result = statemachine.StringList()

ctx.meta["sphinx-click-env"] = self.env
if semantic_group:
Expand Down Expand Up @@ -530,15 +531,15 @@ def _generate_nodes(

return [section]

def run(self) -> ty.Iterable[nodes.section]:
def run(self) -> ty.Sequence[nodes.section]:
self.env = self.state.document.settings.env

command = self._load_module(self.arguments[0])

if 'prog' not in self.options:
raise self.error(':prog: must be specified')

prog_name = self.options.get('prog')
prog_name = self.options['prog']
show_nested = 'show-nested' in self.options
nested = self.options.get('nested')

Expand All @@ -557,7 +558,7 @@ def run(self) -> ty.Iterable[nodes.section]:
commands = None
if self.options.get('commands'):
commands = [
command.strip() for command in self.options.get('commands').split(',')
command.strip() for command in self.options['commands'].split(',')
]

return self._generate_nodes(prog_name, command, None, nested, commands)
Expand Down

0 comments on commit 9dcaf75

Please sign in to comment.