Skip to content

Commit 1d16e6c

Browse files
authored
Replacing Callable[[T], T] with callback protocol in click (#4045)
1 parent 9a16b02 commit 1d16e6c

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

third_party/2and3/click/decorators.pyi

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from distutils.version import Version
2-
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union, Text, overload
2+
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union, Text, overload, Protocol
33

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

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

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

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

2526
def make_pass_decorator(
2627
object_type: type, ensure: bool = ...
27-
) -> Callable[[_T], _T]:
28+
) -> _IdentityFunction:
2829
...
2930

3031

@@ -85,7 +86,7 @@ def argument(
8586
is_eager: bool = ...,
8687
envvar: Optional[Union[str, List[str]]] = ...,
8788
autocompletion: Optional[Callable[[Any, List[str], str], List[Union[str, Tuple[str, str]]]]] = ...,
88-
) -> Callable[[_F], _F]:
89+
) -> _IdentityFunction:
8990
...
9091

9192

@@ -117,7 +118,7 @@ def option(
117118
envvar: Optional[Union[str, List[str]]] = ...,
118119
# User-defined
119120
**kwargs: Any,
120-
) -> Callable[[_F], _F]:
121+
) -> _IdentityFunction:
121122
...
122123

123124

@@ -149,7 +150,7 @@ def option(
149150
envvar: Optional[Union[str, List[str]]] = ...,
150151
# User-defined
151152
**kwargs: Any,
152-
) -> Callable[[_F], _F]:
153+
) -> _IdentityFunction:
153154
...
154155

155156

@@ -181,7 +182,7 @@ def option(
181182
envvar: Optional[Union[str, List[str]]] = ...,
182183
# User-defined
183184
**kwargs: Any,
184-
) -> Callable[[_F], _F]:
185+
) -> _IdentityFunction:
185186
...
186187

187188

@@ -213,7 +214,7 @@ def option(
213214
envvar: Optional[Union[str, List[str]]] = ...,
214215
# User-defined
215216
**kwargs: Any,
216-
) -> Callable[[_F], _F]:
217+
) -> _IdentityFunction:
217218
...
218219

219220

@@ -241,7 +242,7 @@ def confirmation_option(
241242
expose_value: bool = ...,
242243
is_eager: bool = ...,
243244
envvar: Optional[Union[str, List[str]]] = ...
244-
) -> Callable[[_F], _F]:
245+
) -> _IdentityFunction:
245246
...
246247

247248

@@ -269,7 +270,7 @@ def password_option(
269270
expose_value: bool = ...,
270271
is_eager: bool = ...,
271272
envvar: Optional[Union[str, List[str]]] = ...
272-
) -> Callable[[_F], _F]:
273+
) -> _IdentityFunction:
273274
...
274275

275276

@@ -300,7 +301,7 @@ def version_option(
300301
expose_value: bool = ...,
301302
is_eager: bool = ...,
302303
envvar: Optional[Union[str, List[str]]] = ...
303-
) -> Callable[[_F], _F]:
304+
) -> _IdentityFunction:
304305
...
305306

306307

@@ -328,5 +329,5 @@ def help_option(
328329
expose_value: bool = ...,
329330
is_eager: bool = ...,
330331
envvar: Optional[Union[str, List[str]]] = ...
331-
) -> Callable[[_F], _F]:
332+
) -> _IdentityFunction:
332333
...

0 commit comments

Comments
 (0)