Skip to content

Commit

Permalink
Removing type ignore comments from cli package
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshks committed Mar 30, 2020
1 parent 720c77a commit e144c7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions news/770AC380-E84F-44C7-A20C-CD31A829EDA5.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove "type: ignore" comments from cli subpackage
45 changes: 30 additions & 15 deletions src/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Any, Dict, List
from typing import Any, Dict, List, Sequence, Generator

try:
from pip._vendor import colorama
Expand Down Expand Up @@ -78,6 +78,7 @@ def __init__(self, *args, **kwargs):
"""
Save the original SIGINT handler for later.
"""
# https://github.com/python/mypy/issues/5887
super(InterruptibleMixin, self).__init__( # type: ignore
*args,
**kwargs
Expand Down Expand Up @@ -134,6 +135,7 @@ class DownloadProgressMixin(object):

def __init__(self, *args, **kwargs):
# type: (List[Any], Dict[Any, Any]) -> None
# https://github.com/python/mypy/issues/5887
super(DownloadProgressMixin, self).__init__( # type: ignore
*args,
**kwargs
Expand All @@ -145,24 +147,38 @@ def __init__(self, *args, **kwargs):
@property
def downloaded(self):
# type: () -> str
return format_size(self.index) # type: ignore

self.index = getattr(self, 'index')
return format_size(self.index)

@property
def download_speed(self):
# type: () -> str

self.avg = getattr(self, 'avg')

# Avoid zero division errors...
if self.avg == 0.0: # type: ignore
if self.avg == 0.0:
return "..."
return format_size(1 / self.avg) + "/s" # type: ignore
return format_size(1 / self.avg) + "/s"

@property
def pretty_eta(self):
# type: () -> str
if self.eta: # type: ignore
return "eta {}".format(self.eta_td) # type: ignore

self.eta = getattr(self, 'eta')
self.eta_td = getattr(self, 'eta_td')

if self.eta:
return "eta {}".format(self.eta_td)
return ""

def iter(self, it): # type: ignore
def iter(self, it):
# type: (Sequence[Any]) -> Generator[Any, Any, Any]

self.next = getattr(self, 'next')
self.finish = getattr(self, 'finish')

for x in it:
yield x
self.next(len(x))
Expand All @@ -183,6 +199,7 @@ def __init__(self, *args, **kwargs):
if WINDOWS and self.hide_cursor: # type: ignore
self.hide_cursor = False

# https://github.com/python/mypy/issues/5887
super(WindowsMixin, self).__init__(*args, **kwargs) # type: ignore

# Check if we are running on Windows and we have the colorama module,
Expand All @@ -206,30 +223,27 @@ class BaseDownloadProgressBar(WindowsMixin, InterruptibleMixin,
message = "%(percent)d%%"
suffix = "%(downloaded)s %(download_speed)s %(pretty_eta)s"

# NOTE: The "type: ignore" comments on the following classes are there to
# work around https://github.com/python/typing/issues/241


class DefaultDownloadProgressBar(BaseDownloadProgressBar,
_BaseBar):
pass


class DownloadSilentBar(BaseDownloadProgressBar, SilentBar): # type: ignore
class DownloadSilentBar(BaseDownloadProgressBar, SilentBar):
pass


class DownloadBar(BaseDownloadProgressBar, # type: ignore
class DownloadBar(BaseDownloadProgressBar,
Bar):
pass


class DownloadFillingCirclesBar(BaseDownloadProgressBar, # type: ignore
class DownloadFillingCirclesBar(BaseDownloadProgressBar,
FillingCirclesBar):
pass


class DownloadBlueEmojiProgressBar(BaseDownloadProgressBar, # type: ignore
class DownloadBlueEmojiProgressBar(BaseDownloadProgressBar,
BlueEmojiBar):
pass

Expand All @@ -240,7 +254,8 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin,
file = sys.stdout
suffix = "%(downloaded)s %(download_speed)s"

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

0 comments on commit e144c7b

Please sign in to comment.