Skip to content

Commit

Permalink
fix: tighten command typing too
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Mar 30, 2022
1 parent e704701 commit 016df26
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/click/decorators.py
Expand Up @@ -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:
...


Expand All @@ -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]:
...


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 016df26

Please sign in to comment.