Skip to content

Replacing Callable[[T], T] with callback protocol in click #4045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2020
Merged
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
27 changes: 14 additions & 13 deletions third_party/2and3/click/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from distutils.version import Version
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union, Text, overload
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union, Text, overload, Protocol

from click.core import Command, Group, Argument, Option, Parameter, Context, _ConvertibleType

_T = TypeVar('_T')
_F = TypeVar('_F', bound=Callable[..., Any])

# Until https://github.com/python/mypy/issues/3924 is fixed you can't do the following:
# _Decorator = Callable[[_F], _F]
class _IdentityFunction(Protocol):
def __call__(self, __x: _T) -> _T: ...


_Callback = Callable[
[Context, Union[Option, Parameter], Any],
Expand All @@ -24,7 +25,7 @@ def pass_obj(_T) -> _T:

def make_pass_decorator(
object_type: type, ensure: bool = ...
) -> Callable[[_T], _T]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -85,7 +86,7 @@ def argument(
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...,
autocompletion: Optional[Callable[[Any, List[str], str], List[Union[str, Tuple[str, str]]]]] = ...,
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -117,7 +118,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -149,7 +150,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -181,7 +182,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -213,7 +214,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -241,7 +242,7 @@ def confirmation_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -269,7 +270,7 @@ def password_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -300,7 +301,7 @@ def version_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...


Expand Down Expand Up @@ -328,5 +329,5 @@ def help_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> Callable[[_F], _F]:
) -> _IdentityFunction:
...