Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Feb 3, 2024
1 parent cf2a8e2 commit febd7ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/rich_click/rich_help_rendering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
import re
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union

import click

Expand All @@ -22,6 +22,7 @@

from rich_click._compat_click import CLICK_IS_BEFORE_VERSION_8X, CLICK_IS_BEFORE_VERSION_9X, CLICK_IS_VERSION_80
from rich_click.rich_help_formatter import RichHelpFormatter
from rich_click.utils import OptionGroupDict


# Support rich <= 10.6.0
Expand Down Expand Up @@ -369,12 +370,15 @@ def get_rich_options(
if isinstance(param, click.core.Argument) and not formatter.config.group_arguments_options:
argument_group_options.append(param.opts[0])
else:
list_of_option_groups: List[str] = option_groups[-1]["options"] # type: ignore[assignment]
list_of_option_groups = list(option_groups[-1]["options"])
list_of_option_groups.append(param.opts[0])

# If we're not grouping arguments and we got some, prepend before default options
if len(argument_group_options) > 0:
extra_option_group = {"name": formatter.config.arguments_panel_title, "options": argument_group_options}
extra_option_group: OptionGroupDict = {
"name": formatter.config.arguments_panel_title,
"options": argument_group_options,
}
option_groups.insert(len(option_groups) - 1, extra_option_group)

# print("!", option_groups)
Expand Down Expand Up @@ -479,7 +483,7 @@ class MetavarHighlighter(RegexHighlighter):
"pad_edge": formatter.config.style_options_table_pad_edge,
"padding": formatter.config.style_options_table_padding,
}
t_styles.update(option_group.get("table_styles", {})) # type: ignore[arg-type]
t_styles.update(option_group.get("table_styles", {}))
box_style = getattr(box, t_styles.pop("box"), None) # type: ignore[arg-type]

options_table = Table(
Expand Down Expand Up @@ -518,7 +522,7 @@ class MetavarHighlighter(RegexHighlighter):
if command in cmd_group.get("commands", []):
break
else:
commands: List[str] = cmd_groups[-1]["commands"] # type: ignore[assignment]
commands = list(cmd_groups[-1]["commands"])
commands.append(command)

# Print each command group panel
Expand All @@ -532,7 +536,9 @@ class MetavarHighlighter(RegexHighlighter):
"pad_edge": formatter.config.style_commands_table_pad_edge,
"padding": formatter.config.style_commands_table_padding,
}
t_styles.update(cmd_group.get("table_styles", {})) # type: ignore[arg-type]
_e: Dict[str, Any] = {}
extra = cmd_group.get("table_styles", _e)
t_styles.update(extra)
box_style = getattr(box, t_styles.pop("box"), None) # type: ignore[arg-type]

commands_table = Table(
Expand Down
11 changes: 6 additions & 5 deletions src/rich_click/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, Optional, Sequence

from typing_extensions import NotRequired, TypedDict

Expand All @@ -21,13 +21,14 @@ def truthy(o: Any) -> Optional[bool]:
class CommandGroupDict(TypedDict):
"""Specification for command groups."""

name: str
commands: List[str]
name: NotRequired[str]
commands: Sequence[str]
table_styles: NotRequired[Dict[str, Any]]


class OptionGroupDict(TypedDict):
"""Specification for option groups."""

name: str
options: List[str]
name: NotRequired[str]
options: Sequence[str]
table_styles: NotRequired[Dict[str, Any]]

0 comments on commit febd7ee

Please sign in to comment.