@@ -51,10 +51,10 @@ class ProgressBarMixinBase(abc.ABC):
5151 #: are configured
5252 widget_kwargs : types .Dict [str , types .Any ]
5353 #: Custom length function for multibyte characters such as CJK
54- # custom_len: types.Callable[[str], int]
55- custom_len : types . ClassVar [
56- types .Callable [['ProgressBarMixinBase' , str ], int ]
57- ]
54+ # mypy and pyright can't agree on what the correct one is... so we'll
55+ # need to use a helper function :(
56+ # custom_len: types.Callable[['ProgressBarMixinBase', str], int]
57+ custom_len : types . Callable [[ str ], int ]
5858 #: The time the progress bar was started
5959 initial_start_time : types .Optional [datetime ]
6060 #: The interval to poll for updates in seconds if there are updates
@@ -188,7 +188,7 @@ def __init__(
188188 def update (self , * args , ** kwargs ):
189189 ProgressBarMixinBase .update (self , * args , ** kwargs )
190190
191- line = converters .to_unicode (self ._format_line ())
191+ line : str = converters .to_unicode (self ._format_line ())
192192 if not self .enable_colors :
193193 line = utils .no_color (line )
194194
@@ -240,11 +240,11 @@ def _format_widgets(self):
240240 expanding .insert (0 , index )
241241 elif isinstance (widget , str ):
242242 result .append (widget )
243- width -= self .custom_len (widget )
243+ width -= self .custom_len (widget ) # type: ignore
244244 else :
245245 widget_output = converters .to_unicode (widget (self , data ))
246246 result .append (widget_output )
247- width -= self .custom_len (widget_output )
247+ width -= self .custom_len (widget_output ) # type: ignore
248248
249249 count = len (expanding )
250250 while expanding :
@@ -254,7 +254,7 @@ def _format_widgets(self):
254254 count -= 1
255255
256256 widget_output = widget (self , data , portion )
257- width -= self .custom_len (widget_output )
257+ width -= self .custom_len (widget_output ) # type: ignore
258258 result [index ] = widget_output
259259
260260 return result
@@ -303,8 +303,8 @@ def finish(self): # pragma: no cover
303303class StdRedirectMixin (DefaultFdMixin ):
304304 redirect_stderr : bool = False
305305 redirect_stdout : bool = False
306- stdout : base .IO
307- stderr : base .IO
306+ stdout : utils . WrappingIO | base .IO
307+ stderr : utils . WrappingIO | base .IO
308308 _stdout : base .IO
309309 _stderr : base .IO
310310
@@ -428,7 +428,7 @@ class ProgressBar(
428428 you from changing the ProgressBar you should treat it as read only.
429429 '''
430430
431- _iterable : types .Optional [types .Iterable ]
431+ _iterable : types .Optional [types .Iterator ]
432432
433433 _DEFAULT_MAXVAL : Type [base .UnknownLength ] = base .UnknownLength
434434 # update every 50 milliseconds (up to a 20 times per second)
@@ -439,11 +439,11 @@ def __init__(
439439 self ,
440440 min_value : T = 0 ,
441441 max_value : T | types .Type [base .UnknownLength ] | None = None ,
442- widgets : types .List [widgets_module .WidgetBase ] = None ,
442+ widgets : types .Optional [ types . List [widgets_module .WidgetBase ] ] = None ,
443443 left_justify : bool = True ,
444444 initial_value : T = 0 ,
445445 poll_interval : types .Optional [float ] = None ,
446- widget_kwargs : types .Dict [str , types .Any ] = None ,
446+ widget_kwargs : types .Optional [ types . Dict [str , types .Any ] ] = None ,
447447 custom_len : types .Callable [[str ], int ] = utils .len_color ,
448448 max_error = True ,
449449 prefix = None ,
@@ -594,7 +594,7 @@ def percentage(self):
594594 return None
595595 elif self .max_value :
596596 todo = self .value - self .min_value
597- total = self .max_value - self .min_value
597+ total = self .max_value - self .min_value # type: ignore
598598 percentage = 100.0 * todo / total
599599 else :
600600 percentage = 100.0
@@ -631,7 +631,7 @@ def data(self) -> types.Dict[str, types.Any]:
631631 '''
632632 self ._last_update_time = time .time ()
633633 self ._last_update_timer = timeit .default_timer ()
634- elapsed = self .last_update_time - self .start_time
634+ elapsed = self .last_update_time - self .start_time # type: ignore
635635 # For Python 2.7 and higher we have _`timedelta.total_seconds`, but we
636636 # want to support older versions as well
637637 total_seconds_elapsed = utils .deltas_to_seconds (elapsed )
@@ -717,11 +717,16 @@ def __iter__(self):
717717
718718 def __next__ (self ):
719719 try :
720- value = next (self ._iterable )
720+ if self ._iterable is None : # pragma: no cover
721+ value = self .value
722+ else :
723+ value = next (self ._iterable )
724+
721725 if self .start_time is None :
722726 self .start ()
723727 else :
724728 self .update (self .value + 1 )
729+
725730 return value
726731 except StopIteration :
727732 self .finish ()
0 commit comments