Skip to content

Commit

Permalink
Type annotate cli.progress_bars
Browse files Browse the repository at this point in the history
This is mainly to set out examples for annotations of args and kwargs.
  • Loading branch information
McSinyx committed Apr 13, 2020
1 parent 8cca170 commit 3160583
Showing 1 changed file with 15 additions and 12 deletions.
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

0 comments on commit 3160583

Please sign in to comment.