From 603be5e1da0e8e07e79c6931c6dc43a5578fef40 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 3 Apr 2018 10:16:17 -0400 Subject: [PATCH] Fix typehint of click progressbar (#2003) * Fix typehint of click progressbar * Oops -- stubs are *.pyi files --- third_party/2and3/click/_termui_impl.pyi | 12 ++++++++++ third_party/2and3/click/termui.pyi | 28 +++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 third_party/2and3/click/_termui_impl.pyi diff --git a/third_party/2and3/click/_termui_impl.pyi b/third_party/2and3/click/_termui_impl.pyi new file mode 100644 index 000000000..927c54ca5 --- /dev/null +++ b/third_party/2and3/click/_termui_impl.pyi @@ -0,0 +1,12 @@ +from typing import ContextManager, Iterator, Generic, TypeVar + +_T = TypeVar("_T") + +class ProgressBar(object, Generic[_T]): + def update(self, n_steps: int) -> None: ... + def finish(self) -> None: ... + def __enter__(self) -> "ProgressBar[_T]": ... + def __exit__(self, exc_type, exc_value, tb) -> None: ... + def __iter__(self) -> "ProgressBar[_T]": ... + def next(self) -> _T: ... + def __next__(self) -> _T: ... diff --git a/third_party/2and3/click/termui.pyi b/third_party/2and3/click/termui.pyi index eafa09da2..16368999b 100644 --- a/third_party/2and3/click/termui.pyi +++ b/third_party/2and3/click/termui.pyi @@ -1,4 +1,3 @@ -from contextlib import contextmanager from typing import ( Any, Callable, @@ -7,11 +6,13 @@ from typing import ( IO, List, Optional, + overload, Tuple, TypeVar, ) from click.types import _ConvertibleType +from click._termui_impl import ProgressBar as _ProgressBar def hidden_prompt_func(prompt: str) -> str: @@ -62,10 +63,9 @@ def echo_via_pager(text: str, color: Optional[bool] = ...) -> None: _T = TypeVar('_T') - -@contextmanager +@overload def progressbar( - iterable: Optional[Iterable[_T]] = ..., + iterable: Iterable[_T], length: Optional[int] = ..., label: Optional[str] = ..., show_eta: bool = ..., @@ -79,9 +79,27 @@ def progressbar( width: int = ..., file: Optional[IO] = ..., color: Optional[bool] = ..., -) -> Generator[_T, None, None]: +) -> _ProgressBar[_T]: ... +@overload +def progressbar( + iterable: None = ..., + length: Optional[int] = ..., + label: Optional[str] = ..., + show_eta: bool = ..., + show_percent: Optional[bool] = ..., + show_pos: bool = ..., + item_show_func: Optional[Callable[[_T], str]] = ..., + fill_char: str = ..., + empty_char: str = ..., + bar_template: str = ..., + info_sep: str = ..., + width: int = ..., + file: Optional[IO] = ..., + color: Optional[bool] = ..., +) -> _ProgressBar[int]: + ... def clear() -> None: ...