1414from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
1515
1616if MYPY_CHECK_RUNNING :
17- from typing import Any , Dict , List
17+ from typing import Any , Dict , Iterator , List , Tuple
1818
1919try :
2020 from pip ._vendor import colorama
@@ -124,7 +124,7 @@ def update(self):
124124
125125class BlueEmojiBar (IncrementalBar ):
126126
127- suffix = "%( percent)d% %"
127+ suffix = "{ percent:.0f} %"
128128 bar_prefix = " "
129129 bar_suffix = " "
130130 phases = (u"\U0001F539 " , u"\U0001F537 " , u"\U0001F535 " ) # type: Any
@@ -203,8 +203,8 @@ class BaseDownloadProgressBar(WindowsMixin, InterruptibleMixin,
203203 DownloadProgressMixin ):
204204
205205 file = sys .stdout
206- message = "%( percent)d% %"
207- suffix = "%( downloaded)s %( download_speed)s %( pretty_eta)s "
206+ message = "{ percent:.0f} %"
207+ suffix = "{ downloaded} { download_speed} { pretty_eta} "
208208
209209# NOTE: The "type: ignore" comments on the following classes are there to
210210# work around https://github.com/python/typing/issues/241
@@ -238,7 +238,7 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin,
238238 DownloadProgressMixin , Spinner ):
239239
240240 file = sys .stdout
241- suffix = "%( downloaded)s %( download_speed)s "
241+ suffix = "{ downloaded} { download_speed} "
242242
243243 def next_phase (self ): # type: ignore
244244 if not hasattr (self , "_phaser" ):
@@ -247,19 +247,22 @@ def next_phase(self): # type: ignore
247247
248248 def update (self ):
249249 # type: () -> None
250- message = self .message % self
250+ vals = dict (self ._load_vals (
251+ 'downloaded' , 'download_speed' , 'pretty_eta' , 'percent' ))
252+ message = self .message .format (** vals )
251253 phase = self .next_phase ()
252- suffix = self .suffix % self
253- line = '' .join ([
254- message ,
255- " " if message else "" ,
256- phase ,
257- " " if suffix else "" ,
258- suffix ,
259- ])
260-
254+ suffix = self .suffix .format (** vals )
255+ line = " " .join (filter (None , (message , phase , suffix )))
261256 self .writeln (line )
262257
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+
263266
264267BAR_TYPES = {
265268 "off" : (DownloadSilentBar , DownloadSilentBar ),
0 commit comments