14
14
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
15
15
16
16
if MYPY_CHECK_RUNNING :
17
- from typing import Any , Dict , List
17
+ from typing import Any , Dict , List , Sequence , Generator
18
18
19
19
try :
20
20
from pip ._vendor import colorama
@@ -78,6 +78,7 @@ def __init__(self, *args, **kwargs):
78
78
"""
79
79
Save the original SIGINT handler for later.
80
80
"""
81
+ # https://github.com/python/mypy/issues/5887
81
82
super (InterruptibleMixin , self ).__init__ ( # type: ignore
82
83
* args ,
83
84
** kwargs
@@ -134,6 +135,7 @@ class DownloadProgressMixin(object):
134
135
135
136
def __init__ (self , * args , ** kwargs ):
136
137
# type: (List[Any], Dict[Any, Any]) -> None
138
+ # https://github.com/python/mypy/issues/5887
137
139
super (DownloadProgressMixin , self ).__init__ ( # type: ignore
138
140
* args ,
139
141
** kwargs
@@ -145,24 +147,38 @@ def __init__(self, *args, **kwargs):
145
147
@property
146
148
def downloaded (self ):
147
149
# type: () -> str
148
- return format_size (self .index ) # type: ignore
150
+
151
+ self .index = getattr (self , 'index' )
152
+ return format_size (self .index )
149
153
150
154
@property
151
155
def download_speed (self ):
152
156
# type: () -> str
157
+
158
+ self .avg = getattr (self , 'avg' )
159
+
153
160
# Avoid zero division errors...
154
- if self .avg == 0.0 : # type: ignore
161
+ if self .avg == 0.0 :
155
162
return "..."
156
- return format_size (1 / self .avg ) + "/s" # type: ignore
163
+ return format_size (1 / self .avg ) + "/s"
157
164
158
165
@property
159
166
def pretty_eta (self ):
160
167
# 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 )
163
174
return ""
164
175
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
+
166
182
for x in it :
167
183
yield x
168
184
self .next (len (x ))
@@ -183,6 +199,7 @@ def __init__(self, *args, **kwargs):
183
199
if WINDOWS and self .hide_cursor : # type: ignore
184
200
self .hide_cursor = False
185
201
202
+ # https://github.com/python/mypy/issues/5887
186
203
super (WindowsMixin , self ).__init__ (* args , ** kwargs ) # type: ignore
187
204
188
205
# Check if we are running on Windows and we have the colorama module,
@@ -206,30 +223,27 @@ class BaseDownloadProgressBar(WindowsMixin, InterruptibleMixin,
206
223
message = "%(percent)d%%"
207
224
suffix = "%(downloaded)s %(download_speed)s %(pretty_eta)s"
208
225
209
- # NOTE: The "type: ignore" comments on the following classes are there to
210
- # work around https://github.com/python/typing/issues/241
211
-
212
226
213
227
class DefaultDownloadProgressBar (BaseDownloadProgressBar ,
214
228
_BaseBar ):
215
229
pass
216
230
217
231
218
- class DownloadSilentBar (BaseDownloadProgressBar , SilentBar ): # type: ignore
232
+ class DownloadSilentBar (BaseDownloadProgressBar , SilentBar ):
219
233
pass
220
234
221
235
222
- class DownloadBar (BaseDownloadProgressBar , # type: ignore
236
+ class DownloadBar (BaseDownloadProgressBar ,
223
237
Bar ):
224
238
pass
225
239
226
240
227
- class DownloadFillingCirclesBar (BaseDownloadProgressBar , # type: ignore
241
+ class DownloadFillingCirclesBar (BaseDownloadProgressBar ,
228
242
FillingCirclesBar ):
229
243
pass
230
244
231
245
232
- class DownloadBlueEmojiProgressBar (BaseDownloadProgressBar , # type: ignore
246
+ class DownloadBlueEmojiProgressBar (BaseDownloadProgressBar ,
233
247
BlueEmojiBar ):
234
248
pass
235
249
@@ -240,7 +254,8 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin,
240
254
file = sys .stdout
241
255
suffix = "%(downloaded)s %(download_speed)s"
242
256
243
- def next_phase (self ): # type: ignore
257
+ def next_phase (self ):
258
+ # type: () -> str
244
259
if not hasattr (self , "_phaser" ):
245
260
self ._phaser = itertools .cycle (self .phases )
246
261
return next (self ._phaser )
0 commit comments