Skip to content
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

Type annotate cli.progress_bars #8031

Closed
wants to merge 1 commit into from
Closed
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
Empty file.
27 changes: 15 additions & 12 deletions src/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Any, Dict, List
from typing import Any, Callable, Iterable, Iterator, Optional
DownloadProgress = Callable[[Iterable[bytes]], Iterator[bytes]]

try:
from pip._vendor import colorama
Expand Down Expand Up @@ -52,7 +53,7 @@ def _select_progress_class(preferred, fallback):
return preferred


_BaseBar = _select_progress_class(IncrementalBar, Bar) # type: Any
_BaseBar = _select_progress_class(IncrementalBar, Bar) # type: Bar


class InterruptibleMixin(object):
Expand All @@ -74,7 +75,7 @@ class InterruptibleMixin(object):
"""

def __init__(self, *args, **kwargs):
# type: (List[Any], Dict[Any, Any]) -> None
# type: (*Any, **Any) -> None
"""
Save the original SIGINT handler for later.
"""
Expand Down Expand Up @@ -133,14 +134,13 @@ class BlueEmojiBar(IncrementalBar):
class DownloadProgressMixin(object):

def __init__(self, *args, **kwargs):
# type: (List[Any], Dict[Any, Any]) -> None
# type: (*Any, **Any) -> None
super(DownloadProgressMixin, self).__init__( # type: ignore
*args,
**kwargs
)
self.message = (" " * (
get_indentation() + 2
)) + self.message # type: str
indent = " " * (get_indentation() + 2) # type: str
self.message = indent + self.message # type: str

@property
def downloaded(self):
Expand All @@ -162,17 +162,18 @@ def pretty_eta(self):
return "eta {}".format(self.eta_td) # type: ignore
return ""

def iter(self, it): # type: ignore
def iter(self, it):
# type: (Iterable[bytes]) -> Iterator[bytes]
for x in it:
yield x
self.next(len(x))
self.finish()
self.next(len(x)) # type: ignore
self.finish() # type: ignore


class WindowsMixin(object):

def __init__(self, *args, **kwargs):
# type: (List[Any], Dict[Any, Any]) -> None
# type: (*Any, **Any) -> None
# The Windows terminal does not support the hide/show cursor ANSI codes
# even with colorama. So we'll ensure that hide_cursor is False on
# Windows.
Expand Down Expand Up @@ -271,7 +272,9 @@ def update(self):


def DownloadProgressProvider(progress_bar, max=None): # type: ignore
# type: (str, Optional[int]) -> DownloadProgress
if max is None or max == 0:
return BAR_TYPES[progress_bar][1]().iter
# mypy error: "WindowsMixin" has no attribute "iter"
return BAR_TYPES[progress_bar][1]().iter # type: ignore
else:
return BAR_TYPES[progress_bar][0](max=max).iter