|
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, Iterator, List, Tuple |
18 | 18 |
|
19 | 19 | try: |
20 | 20 | from pip._vendor import colorama |
@@ -247,18 +247,22 @@ def next_phase(self): # type: ignore |
247 | 247 |
|
248 | 248 | def update(self): |
249 | 249 | # type: () -> None |
250 | | - vals = dict( |
251 | | - downloaded=self.downloaded, |
252 | | - download_speed=self.download_speed, |
253 | | - pretty_eta=self.pretty_eta, |
254 | | - percent=self.percent, |
255 | | - ) |
| 250 | + vals = dict(self._load_vals( |
| 251 | + 'downloaded', 'download_speed', 'pretty_eta', 'percent')) |
256 | 252 | message = self.message.format(**vals) |
257 | 253 | phase = self.next_phase() |
258 | 254 | suffix = self.suffix.format(**vals) |
259 | 255 | line = " ".join(filter(None, (message, phase, suffix))) |
260 | 256 | self.writeln(line) |
261 | 257 |
|
| 258 | + def _load_vals(self, *names): |
| 259 | + # type: (*str) -> Iterator[Tuple[str, Any]] |
| 260 | + for name in names: |
| 261 | + try: |
| 262 | + yield name, getattr(self, name) |
| 263 | + except Exception: |
| 264 | + pass |
| 265 | + |
262 | 266 |
|
263 | 267 | BAR_TYPES = { |
264 | 268 | "off": (DownloadSilentBar, DownloadSilentBar), |
|
0 commit comments