Skip to content

Commit 7a9a107

Browse files
Move IdentityFunction to _typeshed (#5483)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 02be4b5 commit 7a9a107

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

stdlib/@python2/_typeshed/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ _KT_co = TypeVar("_KT_co", covariant=True)
2222
_KT_contra = TypeVar("_KT_contra", contravariant=True)
2323
_VT = TypeVar("_VT")
2424
_VT_co = TypeVar("_VT_co", covariant=True)
25+
_T = TypeVar("_T")
2526
_T_co = TypeVar("_T_co", covariant=True)
2627
_T_contra = TypeVar("_T_contra", contravariant=True)
2728

29+
class IdentityFunction(Protocol):
30+
def __call__(self, __x: _T) -> _T: ...
31+
2832
class SupportsLessThan(Protocol):
2933
def __lt__(self, __other: Any) -> bool: ...
3034

stdlib/_typeshed/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ _KT_co = TypeVar("_KT_co", covariant=True)
2424
_KT_contra = TypeVar("_KT_contra", contravariant=True)
2525
_VT = TypeVar("_VT")
2626
_VT_co = TypeVar("_VT_co", covariant=True)
27+
_T = TypeVar("_T")
2728
_T_co = TypeVar("_T_co", covariant=True)
2829
_T_contra = TypeVar("_T_contra", contravariant=True)
2930

31+
class IdentityFunction(Protocol):
32+
def __call__(self, __x: _T) -> _T: ...
33+
3034
class SupportsLessThan(Protocol):
3135
def __lt__(self, __other: Any) -> bool: ...
3236

stubs/click/click/decorators.pyi

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
from _typeshed import IdentityFunction
12
from distutils.version import Version
2-
from typing import Any, Callable, Dict, Iterable, List, Optional, Protocol, Text, Tuple, Type, TypeVar, Union, overload
3+
from typing import Any, Callable, Dict, Iterable, List, Optional, Text, Tuple, Type, TypeVar, Union, overload
34

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

67
_T = TypeVar("_T")
78
_F = TypeVar("_F", bound=Callable[..., Any])
89

9-
class _IdentityFunction(Protocol):
10-
def __call__(self, __x: _T) -> _T: ...
11-
1210
_Callback = Callable[[Context, Union[Option, Parameter], Any], Any]
1311

1412
def pass_context(__f: _T) -> _T: ...
1513
def pass_obj(__f: _T) -> _T: ...
16-
def make_pass_decorator(object_type: type, ensure: bool = ...) -> _IdentityFunction: ...
14+
def make_pass_decorator(object_type: type, ensure: bool = ...) -> IdentityFunction: ...
1715

1816
# NOTE: Decorators below have **attrs converted to concrete constructor
1917
# arguments from core.pyi to help with type checking.
@@ -72,7 +70,7 @@ def argument(
7270
is_eager: bool = ...,
7371
envvar: Optional[Union[str, List[str]]] = ...,
7472
autocompletion: Optional[Callable[[Context, List[str], str], Iterable[Union[str, Tuple[str, str]]]]] = ...,
75-
) -> _IdentityFunction: ...
73+
) -> IdentityFunction: ...
7674
@overload
7775
def option(
7876
*param_decls: Text,
@@ -101,7 +99,7 @@ def option(
10199
envvar: Optional[Union[str, List[str]]] = ...,
102100
# User-defined
103101
**kwargs: Any,
104-
) -> _IdentityFunction: ...
102+
) -> IdentityFunction: ...
105103
@overload
106104
def option(
107105
*param_decls: str,
@@ -130,7 +128,7 @@ def option(
130128
envvar: Optional[Union[str, List[str]]] = ...,
131129
# User-defined
132130
**kwargs: Any,
133-
) -> _IdentityFunction: ...
131+
) -> IdentityFunction: ...
134132
@overload
135133
def option(
136134
*param_decls: str,
@@ -159,7 +157,7 @@ def option(
159157
envvar: Optional[Union[str, List[str]]] = ...,
160158
# User-defined
161159
**kwargs: Any,
162-
) -> _IdentityFunction: ...
160+
) -> IdentityFunction: ...
163161
@overload
164162
def option(
165163
*param_decls: str,
@@ -188,7 +186,7 @@ def option(
188186
envvar: Optional[Union[str, List[str]]] = ...,
189187
# User-defined
190188
**kwargs: Any,
191-
) -> _IdentityFunction: ...
189+
) -> IdentityFunction: ...
192190
def confirmation_option(
193191
*param_decls: str,
194192
cls: Type[Option] = ...,
@@ -213,7 +211,7 @@ def confirmation_option(
213211
expose_value: bool = ...,
214212
is_eager: bool = ...,
215213
envvar: Optional[Union[str, List[str]]] = ...,
216-
) -> _IdentityFunction: ...
214+
) -> IdentityFunction: ...
217215
def password_option(
218216
*param_decls: str,
219217
cls: Type[Option] = ...,
@@ -238,7 +236,7 @@ def password_option(
238236
expose_value: bool = ...,
239237
is_eager: bool = ...,
240238
envvar: Optional[Union[str, List[str]]] = ...,
241-
) -> _IdentityFunction: ...
239+
) -> IdentityFunction: ...
242240
def version_option(
243241
version: Optional[Union[str, Version]] = ...,
244242
*param_decls: str,
@@ -266,7 +264,7 @@ def version_option(
266264
expose_value: bool = ...,
267265
is_eager: bool = ...,
268266
envvar: Optional[Union[str, List[str]]] = ...,
269-
) -> _IdentityFunction: ...
267+
) -> IdentityFunction: ...
270268
def help_option(
271269
*param_decls: str,
272270
cls: Type[Option] = ...,
@@ -291,4 +289,4 @@ def help_option(
291289
expose_value: bool = ...,
292290
is_eager: bool = ...,
293291
envvar: Optional[Union[str, List[str]]] = ...,
294-
) -> _IdentityFunction: ...
292+
) -> IdentityFunction: ...

0 commit comments

Comments
 (0)