From dbe5d29788fea277ee488f1852392d3e8cbb32e7 Mon Sep 17 00:00:00 2001 From: Mark Mendoza Date: Tue, 19 May 2020 15:43:45 -0700 Subject: [PATCH 1/2] Replacing Callable[[T], T] with callback protocol in click --- third_party/2and3/click/decorators.pyi | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/third_party/2and3/click/decorators.pyi b/third_party/2and3/click/decorators.pyi index 2df9506acf7a..ecdb42e9ff6c 100644 --- a/third_party/2and3/click/decorators.pyi +++ b/third_party/2and3/click/decorators.pyi @@ -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], @@ -24,7 +25,7 @@ def pass_obj(_T) -> _T: def make_pass_decorator( object_type: type, ensure: bool = ... -) -> Callable[[_T], _T]: +) -> IdentityFunction: ... @@ -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: ... @@ -117,7 +118,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -149,7 +150,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -181,7 +182,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -213,7 +214,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -241,7 +242,7 @@ def confirmation_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -269,7 +270,7 @@ def password_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -300,7 +301,7 @@ def version_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... @@ -328,5 +329,5 @@ def help_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> Callable[[_F], _F]: +) -> IdentityFunction: ... From 7ee611f384638dbf01062d410f6f3510fe39a7bd Mon Sep 17 00:00:00 2001 From: Mark Mendoza Date: Wed, 20 May 2020 13:24:12 -0700 Subject: [PATCH 2/2] IdentityFunction -> _IdentityFunction --- third_party/2and3/click/decorators.pyi | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/third_party/2and3/click/decorators.pyi b/third_party/2and3/click/decorators.pyi index ecdb42e9ff6c..930d1d78bc75 100644 --- a/third_party/2and3/click/decorators.pyi +++ b/third_party/2and3/click/decorators.pyi @@ -6,7 +6,7 @@ from click.core import Command, Group, Argument, Option, Parameter, Context, _Co _T = TypeVar('_T') _F = TypeVar('_F', bound=Callable[..., Any]) -class IdentityFunction(Protocol): +class _IdentityFunction(Protocol): def __call__(self, __x: _T) -> _T: ... @@ -25,7 +25,7 @@ def pass_obj(_T) -> _T: def make_pass_decorator( object_type: type, ensure: bool = ... -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -86,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]]]]] = ..., -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -118,7 +118,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -150,7 +150,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -182,7 +182,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -214,7 +214,7 @@ def option( envvar: Optional[Union[str, List[str]]] = ..., # User-defined **kwargs: Any, -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -242,7 +242,7 @@ def confirmation_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -270,7 +270,7 @@ def password_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -301,7 +301,7 @@ def version_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> IdentityFunction: +) -> _IdentityFunction: ... @@ -329,5 +329,5 @@ def help_option( expose_value: bool = ..., is_eager: bool = ..., envvar: Optional[Union[str, List[str]]] = ... -) -> IdentityFunction: +) -> _IdentityFunction: ...