diff --git a/progressbar/__main__.py b/progressbar/__main__.py index 0bfd7fb..b4b4e9a 100644 --- a/progressbar/__main__.py +++ b/progressbar/__main__.py @@ -62,14 +62,13 @@ def create_argument_parser() -> argparse.ArgumentParser: Create the argument parser for the `progressbar` command. """ - parser = argparse.ArgumentParser( - description=""" + description = """ Monitor the progress of data through a pipe. Note that this is a Python implementation of the original `pv` command that is functional but not yet feature complete. """ - ) + parser = argparse.ArgumentParser(description=description) # Display switches parser.add_argument( diff --git a/progressbar/bar.py b/progressbar/bar.py index 34ba02c..c349370 100644 --- a/progressbar/bar.py +++ b/progressbar/bar.py @@ -368,7 +368,7 @@ def _format_widgets(self): count = len(expanding) while expanding: - portion = max(int(math.ceil(width * 1.0 / count)), 0) + portion = max(math.ceil(width / count), 0) index = expanding.pop() widget = result[index] count -= 1 @@ -410,7 +410,7 @@ def _handle_resize( self, signum: int | None = None, frame: None | FrameType = None ): "Tries to catch resize signals sent from the terminal." - w, h = utils.get_terminal_size() + w, _h = utils.get_terminal_size() self.term_width = w def finish(self): # pragma: no cover @@ -1095,8 +1095,7 @@ def currval(self): progressbar package. """ warnings.warn( - 'The usage of `currval` is deprecated, please use ' - '`value` instead', + 'The usage of `currval` is deprecated, please use `value` instead', DeprecationWarning, stacklevel=1, ) diff --git a/progressbar/env.py b/progressbar/env.py index 3871c2e..d2faae0 100644 --- a/progressbar/env.py +++ b/progressbar/env.py @@ -185,5 +185,5 @@ def is_terminal( 'vt(10[02]|220|320)', ) ANSI_TERM_RE: re.Pattern[str] = re.compile( - f"^({'|'.join(ANSI_TERMS)})", re.IGNORECASE + f'^({"|".join(ANSI_TERMS)})', re.IGNORECASE ) diff --git a/pyproject.toml b/pyproject.toml index 1a484a9..6374f98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -207,7 +207,6 @@ strict = [ reportIncompatibleMethodOverride = false reportUnnecessaryIsInstance = false reportUnnecessaryCast = false -reportUnnecessaryTypeAssertion = false reportUnnecessaryComparison = false reportUnnecessaryContains = false diff --git a/tests/test_stream.py b/tests/test_stream.py index d14845d..e32bbd5 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -99,6 +99,19 @@ def test_no_newlines() -> None: bar.update(i) +def test_update_keeps_colors_when_enabled() -> None: + stream = io.StringIO() + with progressbar.ProgressBar( + fd=stream, + widgets=['\033[92mgreen\033[0m'], + max_value=1, + enable_colors=True, + ) as bar: + bar.update(1) + + assert '\033[92mgreen\033[0m' in stream.getvalue() + + @pytest.mark.parametrize('stream', [sys.__stdout__, sys.__stderr__]) @pytest.mark.skipif(os.name == 'nt', reason='Windows does not support this') def test_fd_as_standard_streams(stream) -> None: