Skip to content

Commit ffd9844

Browse files
committed
Removing type ignore comments from cli package
1 parent 720c77a commit ffd9844

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

news/7764.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove "type: ignore" comments from cli subpackage

src/pip/_internal/cli/progress_bars.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
1515

1616
if MYPY_CHECK_RUNNING:
17-
from typing import Any, Dict, List
17+
from typing import Any, Dict, List, Sequence, Generator
1818

1919
try:
2020
from pip._vendor import colorama
@@ -78,6 +78,7 @@ def __init__(self, *args, **kwargs):
7878
"""
7979
Save the original SIGINT handler for later.
8080
"""
81+
# https://github.com/python/mypy/issues/5887
8182
super(InterruptibleMixin, self).__init__( # type: ignore
8283
*args,
8384
**kwargs
@@ -134,6 +135,7 @@ class DownloadProgressMixin(object):
134135

135136
def __init__(self, *args, **kwargs):
136137
# type: (List[Any], Dict[Any, Any]) -> None
138+
# https://github.com/python/mypy/issues/5887
137139
super(DownloadProgressMixin, self).__init__( # type: ignore
138140
*args,
139141
**kwargs
@@ -145,24 +147,38 @@ def __init__(self, *args, **kwargs):
145147
@property
146148
def downloaded(self):
147149
# type: () -> str
148-
return format_size(self.index) # type: ignore
150+
151+
self.index = getattr(self, 'index')
152+
return format_size(self.index)
149153

150154
@property
151155
def download_speed(self):
152156
# type: () -> str
157+
158+
self.avg = getattr(self, 'avg')
159+
153160
# Avoid zero division errors...
154-
if self.avg == 0.0: # type: ignore
161+
if self.avg == 0.0:
155162
return "..."
156-
return format_size(1 / self.avg) + "/s" # type: ignore
163+
return format_size(1 / self.avg) + "/s"
157164

158165
@property
159166
def pretty_eta(self):
160167
# type: () -> str
161-
if self.eta: # type: ignore
162-
return "eta {}".format(self.eta_td) # type: ignore
168+
169+
self.eta = getattr(self, 'eta')
170+
self.eta_td = getattr(self, 'eta_td')
171+
172+
if self.eta:
173+
return "eta {}".format(self.eta_td)
163174
return ""
164175

165-
def iter(self, it): # type: ignore
176+
def iter(self, it):
177+
# type: (Sequence[Any]) -> Generator[Any, Any, Any]
178+
179+
self.next = getattr(self, 'next')
180+
self.finish = getattr(self, 'finish')
181+
166182
for x in it:
167183
yield x
168184
self.next(len(x))
@@ -183,6 +199,7 @@ def __init__(self, *args, **kwargs):
183199
if WINDOWS and self.hide_cursor: # type: ignore
184200
self.hide_cursor = False
185201

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

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

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

213227
class DefaultDownloadProgressBar(BaseDownloadProgressBar,
214228
_BaseBar):
215229
pass
216230

217231

218-
class DownloadSilentBar(BaseDownloadProgressBar, SilentBar): # type: ignore
232+
class DownloadSilentBar(BaseDownloadProgressBar, SilentBar):
219233
pass
220234

221235

222-
class DownloadBar(BaseDownloadProgressBar, # type: ignore
236+
class DownloadBar(BaseDownloadProgressBar,
223237
Bar):
224238
pass
225239

226240

227-
class DownloadFillingCirclesBar(BaseDownloadProgressBar, # type: ignore
241+
class DownloadFillingCirclesBar(BaseDownloadProgressBar,
228242
FillingCirclesBar):
229243
pass
230244

231245

232-
class DownloadBlueEmojiProgressBar(BaseDownloadProgressBar, # type: ignore
246+
class DownloadBlueEmojiProgressBar(BaseDownloadProgressBar,
233247
BlueEmojiBar):
234248
pass
235249

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

243-
def next_phase(self): # type: ignore
257+
def next_phase(self):
258+
# type: () -> str
244259
if not hasattr(self, "_phaser"):
245260
self._phaser = itertools.cycle(self.phases)
246261
return next(self._phaser)

0 commit comments

Comments
 (0)