1- from __future__ import absolute_import
2- from __future__ import division
3- from __future__ import unicode_literals
4- from __future__ import with_statement
1+ from __future__ import annotations
52
6- import sys
3+ import logging
74import math
85import os
6+ import sys
97import time
108import timeit
11- import logging
129import warnings
13- from datetime import datetime
1410from copy import deepcopy
11+ from datetime import datetime
12+
13+ from python_utils import types
14+
1515try : # pragma: no cover
1616 from collections import abc
1717except ImportError : # pragma: no cover
1818 import collections as abc
1919
2020from python_utils import converters
2121
22- import six
23-
2422from . import widgets
2523from . import widgets as widgets_module # Avoid name collision
2624from . import base
2725from . import utils
2826
29-
3027logger = logging .getLogger (__name__ )
3128
3229
@@ -58,8 +55,10 @@ class ProgressBarBase(abc.Iterable, ProgressBarMixinBase):
5855
5956class DefaultFdMixin (ProgressBarMixinBase ):
6057
61- def __init__ (self , fd = sys .stderr , is_terminal = None , line_breaks = None ,
62- enable_colors = None , ** kwargs ):
58+ def __init__ (self , fd : types .IO = sys .stderr ,
59+ is_terminal : bool | None = None ,
60+ line_breaks : bool | None = None ,
61+ enable_colors : bool | None = None , ** kwargs ):
6362 if fd is sys .stdout :
6463 fd = utils .streams .original_stdout
6564
@@ -76,8 +75,8 @@ def __init__(self, fd=sys.stderr, is_terminal=None, line_breaks=None,
7675 # Check if it should overwrite the current line (suitable for
7776 # iteractive terminals) or write line breaks (suitable for log files)
7877 if line_breaks is None :
79- line_breaks = utils .env_flag ('PROGRESSBAR_LINE_BREAKS' , not
80- self .is_terminal )
78+ line_breaks = utils .env_flag ('PROGRESSBAR_LINE_BREAKS' ,
79+ not self .is_terminal )
8180 self .line_breaks = line_breaks
8281
8382 # Check if ANSI escape characters are enabled (suitable for iteractive
@@ -122,7 +121,7 @@ def finish(self, *args, **kwargs): # pragma: no cover
122121
123122class ResizableMixin (ProgressBarMixinBase ):
124123
125- def __init__ (self , term_width = None , ** kwargs ):
124+ def __init__ (self , term_width : int | None = None , ** kwargs ):
126125 ProgressBarMixinBase .__init__ (self , ** kwargs )
127126
128127 self .signal_set = False
@@ -156,7 +155,8 @@ def finish(self): # pragma: no cover
156155
157156class StdRedirectMixin (DefaultFdMixin ):
158157
159- def __init__ (self , redirect_stderr = False , redirect_stdout = False , ** kwargs ):
158+ def __init__ (self , redirect_stderr : bool = False ,
159+ redirect_stdout : bool = False , ** kwargs ):
160160 DefaultFdMixin .__init__ (self , ** kwargs )
161161 self .redirect_stderr = redirect_stderr
162162 self .redirect_stdout = redirect_stdout
@@ -179,7 +179,7 @@ def start(self, *args, **kwargs):
179179 utils .streams .start_capturing (self )
180180 DefaultFdMixin .start (self , * args , ** kwargs )
181181
182- def update (self , value = None ):
182+ def update (self , value : float = None ):
183183 if not self .line_breaks and utils .streams .needs_clear ():
184184 self .fd .write ('\r ' + ' ' * self .term_width + '\r ' )
185185
@@ -197,7 +197,6 @@ def finish(self, end='\n'):
197197
198198
199199class ProgressBar (StdRedirectMixin , ResizableMixin , ProgressBarBase ):
200-
201200 '''The ProgressBar class which updates and prints the bar.
202201
203202 Args:
@@ -488,8 +487,8 @@ def data(self):
488487 # The seconds since the bar started
489488 total_seconds_elapsed = total_seconds_elapsed ,
490489 # The seconds since the bar started modulo 60
491- seconds_elapsed = (elapsed .seconds % 60 ) +
492- (elapsed .microseconds / 1000000. ),
490+ seconds_elapsed = (elapsed .seconds % 60 )
491+ + (elapsed .microseconds / 1000000. ),
493492 # The minutes since the bar started modulo 60
494493 minutes_elapsed = (elapsed .seconds / 60 ) % 60 ,
495494 # The hours since the bar started modulo 24
@@ -585,7 +584,7 @@ def _format_widgets(self):
585584 elif isinstance (widget , widgets .AutoWidthWidgetBase ):
586585 result .append (widget )
587586 expanding .insert (0 , index )
588- elif isinstance (widget , six . string_types ):
587+ elif isinstance (widget , str ):
589588 result .append (widget )
590589 width -= self .custom_len (widget )
591590 else :
@@ -795,6 +794,7 @@ class DataTransferBar(ProgressBar):
795794
796795 This assumes that the values its given are numbers of bytes.
797796 '''
797+
798798 def default_widgets (self ):
799799 if self .max_value :
800800 return [
@@ -813,7 +813,6 @@ def default_widgets(self):
813813
814814
815815class NullBar (ProgressBar ):
816-
817816 '''
818817 Progress bar that does absolutely nothing. Useful for single verbosity
819818 flags
0 commit comments