summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormatejcik <ja@matejcik.cz>2022-03-11 10:28:42 +0100
committermatejcik <ja@matejcik.cz>2022-03-11 11:23:16 +0100
commita0bbbf2033c6b4eab480c53e6cbb0fd2d737badd (patch)
tree9e903d19b4a2ee34f07836d5ca16721ee4d294bd /src
parentd14ee193d01096113d5de0428b8552bcd5f368e9 (diff)
downloadclick-a0bbbf2033c6b4eab480c53e6cbb0fd2d737badd.tar.gz
correctly annotate return type of @command(cls=XYZ)
Diffstat (limited to 'src')
-rw-r--r--src/click/decorators.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/click/decorators.py b/src/click/decorators.py
index d7b1724..05d1334 100644
--- a/src/click/decorators.py
+++ b/src/click/decorators.py
@@ -121,19 +121,38 @@ def pass_meta_key(
return decorator
+CmdType = t.TypeVar("CmdType", bound=Command)
+
+
+@t.overload
+def command(
+ name: t.Optional[str] = None,
+ cls: t.Type[CmdType] = ...,
+ **attrs: t.Any,
+) -> t.Callable[..., CmdType]:
+ ...
+
+
@t.overload
def command(
name: t.Optional[str] = None,
- cls: t.Optional[t.Type[Command]] = None,
**attrs: t.Any,
-) -> t.Callable[[F], Command]:
+) -> t.Callable[..., Command]:
+ ...
+
+
+@t.overload
+def command(
+ name: t.Callable,
+ cls: t.Type[CmdType] = ...,
+ **attrs: t.Any,
+) -> CmdType:
...
@t.overload
def command(
name: t.Callable,
- cls: t.Optional[t.Type[Command]] = None,
**attrs: t.Any,
) -> Command:
...
@@ -143,7 +162,7 @@ def command(
name: t.Union[str, t.Callable, None] = None,
cls: t.Optional[t.Type[Command]] = None,
**attrs: t.Any,
-) -> t.Union[Command, t.Callable[[F], Command]]:
+) -> t.Union[Command, t.Callable[..., Command]]:
r"""Creates a new :class:`Command` and uses the decorated function as
callback. This will also automatically attach all decorated
:func:`option`\s and :func:`argument`\s as parameters to the command.