Skip to content

Commit 2899d0a

Browse files
eurestiJelleZijlstra
authored andcommitted
Make click decorators not modify the type (#2322)
1 parent 0bc98a1 commit 2899d0a

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

third_party/2and3/click/core.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class Command(BaseCommand):
239239

240240

241241
_T = TypeVar('_T')
242-
_Decorator = Callable[[_T], _T]
242+
_F = TypeVar('_F', bound=Callable[..., Any])
243243

244244

245245
class MultiCommand(Command):
@@ -263,7 +263,7 @@ class MultiCommand(Command):
263263

264264
def resultcallback(
265265
self, replace: bool = ...
266-
) -> _Decorator:
266+
) -> Callable[[_F], _F]:
267267
...
268268

269269
def format_commands(self, ctx: Context, formatter: HelpFormatter) -> None:
@@ -292,10 +292,10 @@ class Group(MultiCommand):
292292
def add_command(self, cmd: Command, name: Optional[str] = ...):
293293
...
294294

295-
def command(self, *args, **kwargs) -> _Decorator:
295+
def command(self, *args, **kwargs) -> Callable[[_F], _F]:
296296
...
297297

298-
def group(self, *args, **kwargs) -> _Decorator:
298+
def group(self, *args, **kwargs) -> Callable[[_F], _F]:
299299
...
300300

301301

third_party/2and3/click/decorators.pyi

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, Te
44
from click.core import Command, Group, Argument, Option, Parameter, Context, _ConvertibleType
55

66
_T = TypeVar('_T')
7-
_Decorator = Callable[[_T], _T]
7+
_F = TypeVar('_F', bound=Callable[..., Any])
8+
9+
# Until https://github.com/python/mypy/issues/3924 is fixed you can't do the following:
10+
# _Decorator = Callable[[_F], _F]
811

912
_Callback = Callable[
1013
[Context, Union[Option, Parameter], Union[bool, int, str]],
@@ -38,7 +41,7 @@ def command(
3841
short_help: Optional[str] = ...,
3942
options_metavar: str = ...,
4043
add_help_option: bool = ...,
41-
) -> _Decorator:
44+
) -> Callable[[_F], _F]:
4245
...
4346

4447

@@ -63,7 +66,7 @@ def group(
6366
add_help_option: bool = ...,
6467
# User-defined
6568
**kwargs: Any,
66-
) -> _Decorator:
69+
) -> Callable[[_F], _F]:
6770
...
6871

6972

@@ -81,7 +84,7 @@ def argument(
8184
expose_value: bool = ...,
8285
is_eager: bool = ...,
8386
envvar: Optional[Union[str, List[str]]] = ...
84-
) -> _Decorator:
87+
) -> Callable[[_F], _F]:
8588
...
8689

8790

@@ -111,7 +114,7 @@ def option(
111114
envvar: Optional[Union[str, List[str]]] = ...,
112115
# User-defined
113116
**kwargs: Any,
114-
) -> _Decorator:
117+
) -> Callable[[_F], _F]:
115118
...
116119

117120

@@ -138,7 +141,7 @@ def confirmation_option(
138141
expose_value: bool = ...,
139142
is_eager: bool = ...,
140143
envvar: Optional[Union[str, List[str]]] = ...
141-
) -> _Decorator:
144+
) -> Callable[[_F], _F]:
142145
...
143146

144147

@@ -165,7 +168,7 @@ def password_option(
165168
expose_value: bool = ...,
166169
is_eager: bool = ...,
167170
envvar: Optional[Union[str, List[str]]] = ...
168-
) -> _Decorator:
171+
) -> Callable[[_F], _F]:
169172
...
170173

171174

@@ -195,7 +198,7 @@ def version_option(
195198
expose_value: bool = ...,
196199
is_eager: bool = ...,
197200
envvar: Optional[Union[str, List[str]]] = ...
198-
) -> _Decorator:
201+
) -> Callable[[_F], _F]:
199202
...
200203

201204

@@ -222,5 +225,5 @@ def help_option(
222225
expose_value: bool = ...,
223226
is_eager: bool = ...,
224227
envvar: Optional[Union[str, List[str]]] = ...
225-
) -> _Decorator:
228+
) -> Callable[[_F], _F]:
226229
...

third_party/2and3/click/utils.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Any, Callable, Iterator, IO, List, Optional, TypeVar, Union, Text
22

33
_T = TypeVar('_T')
4-
_Decorator = Callable[[_T], _T]
54

65

76
def _posixify(name: str) -> str:

0 commit comments

Comments
 (0)