From 3b52d051667c82eb1521b0d648eec7ec5e74082f Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 30 Mar 2022 10:05:24 -0400 Subject: [PATCH] fix: same fix applied to group --- src/click/core.py | 15 +++++++++++++-- src/click/decorators.py | 9 ++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index 59d09ad0d..bd80ab457 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1857,6 +1857,16 @@ def decorator(f: t.Callable[..., t.Any]) -> Command: return decorator + @t.overload + def group(self, __func: t.Callable[..., t.Any]) -> "Group": + ... + + @t.overload + def group( + self, *args: t.Any, **kwargs: t.Any + ) -> t.Callable[[t.Callable[..., t.Any]], "Group"]: + ... + def group( self, *args: t.Any, **kwargs: t.Any ) -> t.Union[t.Callable[[t.Callable[..., t.Any]], "Group"], "Group"]: @@ -1879,8 +1889,9 @@ def group( func: t.Optional[t.Callable] = None if args and callable(args[0]): - func = args[0] - args = args[1:] + assert len(args) == 1, "Please use group(...)(callable) instead" + assert not kwargs, "Please use group(...)(callable) instead" + func, *args = args if self.group_class is not None and kwargs.get("cls") is None: if self.group_class is type: diff --git a/src/click/decorators.py b/src/click/decorators.py index 191a002e7..d55d22312 100644 --- a/src/click/decorators.py +++ b/src/click/decorators.py @@ -228,17 +228,16 @@ def decorator(f: t.Callable[..., t.Any]) -> Command: @t.overload def group( - name: t.Optional[str] = None, - **attrs: t.Any, -) -> t.Callable[[F], Group]: + __name: t.Callable, +) -> Group: ... @t.overload def group( - name: t.Callable, + name: t.Optional[str] = None, **attrs: t.Any, -) -> Group: +) -> t.Callable[[F], Group]: ...