Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.. currentmodule:: click

Version 8.1.5
-------------

Unreleased

- Fix type annotations on the option and argument decorators. :issue:`2558`

Version 8.1.4
-------------

Expand Down
13 changes: 6 additions & 7 deletions src/click/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
R = t.TypeVar("R")
T = t.TypeVar("T")
_AnyCallable = t.Callable[..., t.Any]
_Decorator: "te.TypeAlias" = t.Callable[[T], T]
FC = t.TypeVar("FC", bound=t.Union[_AnyCallable, Command])


Expand Down Expand Up @@ -331,7 +330,7 @@ def _param_memo(f: t.Callable[..., t.Any], param: Parameter) -> None:

def argument(
*param_decls: str, cls: t.Optional[t.Type[Argument]] = None, **attrs: t.Any
) -> _Decorator[FC]:
) -> t.Callable[[FC], FC]:
"""Attaches an argument to the command. All positional arguments are
passed as parameter declarations to :class:`Argument`; all keyword
arguments are forwarded unchanged (except ``cls``).
Expand Down Expand Up @@ -359,7 +358,7 @@ def decorator(f: FC) -> FC:

def option(
*param_decls: str, cls: t.Optional[t.Type[Option]] = None, **attrs: t.Any
) -> _Decorator[FC]:
) -> t.Callable[[FC], FC]:
"""Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
Expand All @@ -385,7 +384,7 @@ def decorator(f: FC) -> FC:
return decorator


def confirmation_option(*param_decls: str, **kwargs: t.Any) -> _Decorator[FC]:
def confirmation_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
"""Add a ``--yes`` option which shows a prompt before continuing if
not passed. If the prompt is declined, the program will exit.

Expand All @@ -409,7 +408,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
return option(*param_decls, **kwargs)


def password_option(*param_decls: str, **kwargs: t.Any) -> _Decorator[FC]:
def password_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
"""Add a ``--password`` option which prompts for a password, hiding
input and asking to enter the value again for confirmation.

Expand All @@ -433,7 +432,7 @@ def version_option(
prog_name: t.Optional[str] = None,
message: t.Optional[str] = None,
**kwargs: t.Any,
) -> _Decorator[FC]:
) -> t.Callable[[FC], FC]:
"""Add a ``--version`` option which immediately prints the version
number and exits the program.

Expand Down Expand Up @@ -539,7 +538,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
return option(*param_decls, **kwargs)


def help_option(*param_decls: str, **kwargs: t.Any) -> _Decorator[FC]:
def help_option(*param_decls: str, **kwargs: t.Any) -> t.Callable[[FC], FC]:
"""Add a ``--help`` option which immediately prints the help page
and exits the program.

Expand Down