Skip to content

Move IdentityFunction to _typeshed #5483

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
May 17, 2021
Merged
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
4 changes: 4 additions & 0 deletions stdlib/@python2/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ _KT_co = TypeVar("_KT_co", covariant=True)
_KT_contra = TypeVar("_KT_contra", contravariant=True)
_VT = TypeVar("_VT")
_VT_co = TypeVar("_VT_co", covariant=True)
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_contra = TypeVar("_T_contra", contravariant=True)

class IdentityFunction(Protocol):
def __call__(self, __x: _T) -> _T: ...

class SupportsLessThan(Protocol):
def __lt__(self, __other: Any) -> bool: ...

Expand Down
4 changes: 4 additions & 0 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ _KT_co = TypeVar("_KT_co", covariant=True)
_KT_contra = TypeVar("_KT_contra", contravariant=True)
_VT = TypeVar("_VT")
_VT_co = TypeVar("_VT_co", covariant=True)
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_contra = TypeVar("_T_contra", contravariant=True)

class IdentityFunction(Protocol):
def __call__(self, __x: _T) -> _T: ...

class SupportsLessThan(Protocol):
def __lt__(self, __other: Any) -> bool: ...

Expand Down
26 changes: 12 additions & 14 deletions stubs/click/click/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from _typeshed import IdentityFunction
from distutils.version import Version
from typing import Any, Callable, Dict, Iterable, List, Optional, Protocol, Text, Tuple, Type, TypeVar, Union, overload
from typing import Any, Callable, Dict, Iterable, List, Optional, Text, Tuple, Type, TypeVar, Union, overload

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

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

class _IdentityFunction(Protocol):
def __call__(self, __x: _T) -> _T: ...

_Callback = Callable[[Context, Union[Option, Parameter], Any], Any]

def pass_context(__f: _T) -> _T: ...
def pass_obj(__f: _T) -> _T: ...
def make_pass_decorator(object_type: type, ensure: bool = ...) -> _IdentityFunction: ...
def make_pass_decorator(object_type: type, ensure: bool = ...) -> IdentityFunction: ...

# NOTE: Decorators below have **attrs converted to concrete constructor
# arguments from core.pyi to help with type checking.
Expand Down Expand Up @@ -72,7 +70,7 @@ def argument(
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...,
autocompletion: Optional[Callable[[Context, List[str], str], Iterable[Union[str, Tuple[str, str]]]]] = ...,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
@overload
def option(
*param_decls: Text,
Expand Down Expand Up @@ -101,7 +99,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
@overload
def option(
*param_decls: str,
Expand Down Expand Up @@ -130,7 +128,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
@overload
def option(
*param_decls: str,
Expand Down Expand Up @@ -159,7 +157,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
@overload
def option(
*param_decls: str,
Expand Down Expand Up @@ -188,7 +186,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
def confirmation_option(
*param_decls: str,
cls: Type[Option] = ...,
Expand All @@ -213,7 +211,7 @@ def confirmation_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
def password_option(
*param_decls: str,
cls: Type[Option] = ...,
Expand All @@ -238,7 +236,7 @@ def password_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
def version_option(
version: Optional[Union[str, Version]] = ...,
*param_decls: str,
Expand Down Expand Up @@ -266,7 +264,7 @@ def version_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...
def help_option(
*param_decls: str,
cls: Type[Option] = ...,
Expand All @@ -291,4 +289,4 @@ def help_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...,
) -> _IdentityFunction: ...
) -> IdentityFunction: ...