Skip to content

Commit

Permalink
Complete the annotations in pip/_internal/cli
Browse files Browse the repository at this point in the history
This is the second part of my job made on pypa#10018, where I must complete all the annotations from `pip/_internal/cli`.
  • Loading branch information
DiddiLeija committed Jun 14, 2021
1 parent c44b23c commit ff6b13a
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/pip/_internal/cli/progress_bars.py
Expand Up @@ -18,8 +18,7 @@
colorama = None


def _select_progress_class(preferred, fallback):
# type: (Bar, Bar) -> Bar
def _select_progress_class(preferred: Bar, fallback: Bar) -> Bar:
encoding = getattr(preferred.file, "encoding", None)

# If we don't know what encoding this file is in, then we'll just assume
Expand Down Expand Up @@ -67,8 +66,7 @@ class InterruptibleMixin:
download has already completed, for example.
"""

def __init__(self, *args, **kwargs):
# type: (List[Any], Dict[Any, Any]) -> None
def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None:
"""
Save the original SIGINT handler for later.
"""
Expand All @@ -85,8 +83,7 @@ def __init__(self, *args, **kwargs):
if self.original_handler is None:
self.original_handler = default_int_handler

def finish(self):
# type: () -> None
def finish(self) -> None:
"""
Restore the original SIGINT handler after finishing.
Expand All @@ -108,8 +105,7 @@ def handle_sigint(self, signum, frame): # type: ignore


class SilentBar(Bar):
def update(self):
# type: () -> None
def update(self) -> None:
pass


Expand All @@ -122,28 +118,25 @@ class BlueEmojiBar(IncrementalBar):


class DownloadProgressMixin:
def __init__(self, *args, **kwargs):
def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None:
# type: (List[Any], Dict[Any, Any]) -> None
# https://github.com/python/mypy/issues/5887
super().__init__(*args, **kwargs) # type: ignore
self.message = (" " * (get_indentation() + 2)) + self.message # type: str

@property
def downloaded(self):
# type: () -> str
def downloaded(self) -> str:
return format_size(self.index) # type: ignore

@property
def download_speed(self):
# type: () -> str
def download_speed(self) -> str:
# Avoid zero division errors...
if self.avg == 0.0: # type: ignore
return "..."
return format_size(1 / self.avg) + "/s" # type: ignore

@property
def pretty_eta(self):
# type: () -> str
def pretty_eta(self) -> str:
if self.eta: # type: ignore
return f"eta {self.eta_td}" # type: ignore
return ""
Expand All @@ -158,8 +151,7 @@ def iter(self, it): # type: ignore


class WindowsMixin:
def __init__(self, *args, **kwargs):
# type: (List[Any], Dict[Any, Any]) -> None
def __init__(self, *args: List[Any], **kwargs: Dict[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 @@ -221,14 +213,12 @@ class DownloadProgressSpinner(
file = sys.stdout
suffix = "%(downloaded)s %(download_speed)s"

def next_phase(self):
# type: () -> str
def next_phase(self) -> str:
if not hasattr(self, "_phaser"):
self._phaser = itertools.cycle(self.phases)
return next(self._phaser)

def update(self):
# type: () -> None
def update(self) -> None:
message = self.message % self
phase = self.next_phase()
suffix = self.suffix % self
Expand Down

0 comments on commit ff6b13a

Please sign in to comment.