Skip to content

Commit

Permalink
Make click decorators not modify the type (python#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
euresti authored and Jiri Suchan committed Jan 23, 2019
1 parent 6cc62d2 commit ed76cda
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions third_party/2and3/click/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class Command(BaseCommand):


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


class MultiCommand(Command):
Expand All @@ -263,7 +263,7 @@ class MultiCommand(Command):

def resultcallback(
self, replace: bool = ...
) -> _Decorator:
) -> Callable[[_F], _F]:
...

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

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

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


Expand Down
21 changes: 12 additions & 9 deletions third_party/2and3/click/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, Te
from click.core import Command, Group, Argument, Option, Parameter, Context, _ConvertibleType

_T = TypeVar('_T')
_Decorator = Callable[[_T], _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]

_Callback = Callable[
[Context, Union[Option, Parameter], Union[bool, int, str]],
Expand Down Expand Up @@ -38,7 +41,7 @@ def command(
short_help: Optional[str] = ...,
options_metavar: str = ...,
add_help_option: bool = ...,
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand All @@ -63,7 +66,7 @@ def group(
add_help_option: bool = ...,
# User-defined
**kwargs: Any,
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand All @@ -81,7 +84,7 @@ def argument(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand Down Expand Up @@ -111,7 +114,7 @@ def option(
envvar: Optional[Union[str, List[str]]] = ...,
# User-defined
**kwargs: Any,
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand All @@ -138,7 +141,7 @@ def confirmation_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand All @@ -165,7 +168,7 @@ def password_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand Down Expand Up @@ -195,7 +198,7 @@ def version_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> _Decorator:
) -> Callable[[_F], _F]:
...


Expand All @@ -222,5 +225,5 @@ def help_option(
expose_value: bool = ...,
is_eager: bool = ...,
envvar: Optional[Union[str, List[str]]] = ...
) -> _Decorator:
) -> Callable[[_F], _F]:
...
1 change: 0 additions & 1 deletion third_party/2and3/click/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, Callable, Iterator, IO, List, Optional, TypeVar, Union, Text

_T = TypeVar('_T')
_Decorator = Callable[[_T], _T]


def _posixify(name: str) -> str:
Expand Down

0 comments on commit ed76cda

Please sign in to comment.