Skip to content

Commit

Permalink
Add return type to @command
Browse files Browse the repository at this point in the history
  • Loading branch information
janluke committed Feb 27, 2021
1 parent f3dd267 commit 92f5572
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 4 additions & 8 deletions cloup/_commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import abc
from typing import (
Dict,
Iterable,
Optional,
Type,
)
from typing import Callable, Dict, Iterable, Optional, Type, cast

import click

Expand Down Expand Up @@ -114,7 +109,7 @@ def command(
name: Optional[str] = None,
cls: Type[click.Command] = Command,
**attrs
):
) -> Callable[[Callable], click.Command]:
"""
Decorator that creates a new command using the wrapped function as callback.
Expand All @@ -138,6 +133,7 @@ def wrapper(f):
del f.__constraints
attrs['constraints'] = constraints

return click.command(name, cls=cls, **attrs)(f)
cmd = click.command(name, cls=cls, **attrs)(f)
return cast(click.Command, cmd)

return wrapper
3 changes: 2 additions & 1 deletion tests/constraints/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import cast
from unittest.mock import Mock

import click
Expand Down Expand Up @@ -43,4 +44,4 @@ def sample_cmd() -> Command:
def f(**kwargs):
print('It works')

return f
return cast(Command, f)

0 comments on commit 92f5572

Please sign in to comment.