From 9c199355ffa9e4693279c8180abc3ea74220a8ab Mon Sep 17 00:00:00 2001 From: dwreeves Date: Sun, 10 Dec 2023 23:46:51 -0500 Subject: [PATCH] fix --- src/rich_click/rich_command.py | 40 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/rich_click/rich_command.py b/src/rich_click/rich_command.py index 504d2b14..a7e55bf2 100644 --- a/src/rich_click/rich_command.py +++ b/src/rich_click/rich_command.py @@ -186,15 +186,16 @@ def format_options(self, ctx: RichContext, formatter: RichHelpFormatter) -> None def format_epilog(self, ctx: RichContext, formatter: RichHelpFormatter) -> None: # type: ignore[override] get_rich_epilog(self, ctx, formatter) - if CLICK_IS_BEFORE_VERSION_8X: - - def make_context( - self, - info_name: Optional[str], - args: List[str], - parent: Optional[click.Context] = None, - **extra: Any, - ) -> RichContext: + def make_context( + self, + info_name: Optional[str], + args: List[str], + parent: Optional[click.Context] = None, + **extra: Any, + ) -> RichContext: + if CLICK_IS_BEFORE_VERSION_8X: + # Reimplement Click 8.x logic. + for key, value in self.context_settings.items(): if key not in extra: extra[key] = value @@ -205,15 +206,7 @@ def make_context( self.parse_args(ctx, args) return ctx - else: - - def make_context( - self, - info_name: Optional[str], - args: List[str], - parent: Optional[click.Context] = None, - **extra: Any, - ) -> RichContext: + else: return super().make_context(info_name, args, parent, **extra) # type: ignore[return-value] @@ -245,7 +238,7 @@ def command(self, *args: Any, **kwargs: Any) -> Callable[[Callable[..., Any]], R def command(self, *args: Any, **kwargs: Any) -> Union[Callable[[Callable[..., Any]], RichCommand], RichCommand]: # This method override is required for Click 7.x compatibility. # (The command_class ClassVar was not added until 8.0.) - if self.command_class is not None: + if CLICK_IS_BEFORE_VERSION_8X: kwargs.setdefault("cls", self.command_class) return super().command(*args, **kwargs) # type: ignore[no-any-return] @@ -260,10 +253,11 @@ def group(self, *args: Any, **kwargs: Any) -> Callable[[Callable[..., Any]], "Ri def group(self, *args: Any, **kwargs: Any) -> Union[Callable[[Callable[..., Any]], "RichGroup"], "RichGroup"]: # This method override is required for Click 7.x compatibility. # (The group_class ClassVar was not added until 8.0.) - if self.group_class is type: - kwargs.setdefault("cls", self.__class__) - elif self.group_class is not None: - kwargs.setdefault("cls", self.group_class) + if CLICK_IS_BEFORE_VERSION_8X: + if self.group_class is type: + kwargs.setdefault("cls", self.__class__) + else: + kwargs.setdefault("cls", self.group_class) return super().group(*args, **kwargs) # type: ignore[no-any-return]