From 016df269928362528ac0777478e908b1dc28850f Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 30 Mar 2022 09:59:44 -0400 Subject: [PATCH] fix: tighten command typing too --- src/click/decorators.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/click/decorators.py b/src/click/decorators.py index 05d133443..191a002e7 100644 --- a/src/click/decorators.py +++ b/src/click/decorators.py @@ -126,10 +126,8 @@ def new_func(*args, **kwargs): # type: ignore @t.overload def command( - name: t.Optional[str] = None, - cls: t.Type[CmdType] = ..., - **attrs: t.Any, -) -> t.Callable[..., CmdType]: + __name: t.Callable[..., t.Any], +) -> Command: ... @@ -143,18 +141,10 @@ def command( @t.overload def command( - name: t.Callable, + name: t.Optional[str] = None, cls: t.Type[CmdType] = ..., **attrs: t.Any, -) -> CmdType: - ... - - -@t.overload -def command( - name: t.Callable, - **attrs: t.Any, -) -> Command: +) -> t.Callable[..., CmdType]: ... @@ -191,14 +181,17 @@ def command( The ``params`` argument can be used. Decorated params are appended to the end of the list. """ - if cls is None: - cls = Command func: t.Optional[t.Callable] = None if callable(name): func = name name = None + assert cls is None, "Please use command(name, cls)(callable) instead" + assert not attrs, "Please use command(name, **attrs)(callable) instead" + + if cls is None: + cls = Command def decorator(f: t.Callable[..., t.Any]) -> Command: if isinstance(f, Command):