diff options
author | David Lord <davidism@gmail.com> | 2022-03-17 11:52:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-17 11:52:51 -0700 |
commit | 5ba2320454065a78dbb4176e582ab21c990d358c (patch) | |
tree | 9e903d19b4a2ee34f07836d5ca16721ee4d294bd /src | |
parent | d14ee193d01096113d5de0428b8552bcd5f368e9 (diff) | |
parent | a0bbbf2033c6b4eab480c53e6cbb0fd2d737badd (diff) | |
download | click-5ba2320454065a78dbb4176e582ab21c990d358c.tar.gz |
Merge pull request #2212 from matejcik/type-hints
Improve type hints
Diffstat (limited to 'src')
-rw-r--r-- | src/click/decorators.py | 27 |
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. |