From 9b84cdb64dfa0f166b9ef93cb1e76f70694dba63 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 16 Oct 2024 07:38:06 +0100 Subject: [PATCH 1/3] used Sized for Progress bar --- spinn_utilities/progress_bar.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spinn_utilities/progress_bar.py b/spinn_utilities/progress_bar.py index 3b4e3ebe..7c062bcd 100644 --- a/spinn_utilities/progress_bar.py +++ b/spinn_utilities/progress_bar.py @@ -13,12 +13,13 @@ # limitations under the License. from collections import defaultdict +from collections.abc import Sized from datetime import date import logging import math import os import sys -from typing import Dict, Iterable, List, TypeVar +from typing import Dict, Iterable, List, TypeVar, Union from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter from spinn_utilities.overrides import overrides @@ -46,15 +47,14 @@ class ProgressBar(object): "_step_character", "_end_character", "_in_bad_terminal", ) - def __init__(self, total_number_of_things_to_do, + def __init__(self, total_number_of_things_to_do: Union[int, Sized], string_describing_what_being_progressed, step_character="=", end_character="|"): try: self._number_of_things = int(total_number_of_things_to_do) except TypeError: - # Might be dealing with general iterable; better not be infinite - self._number_of_things = len(list(total_number_of_things_to_do)) + self._number_of_things = len(total_number_of_things_to_do) self._currently_completed = 0 self._chars_per_thing = None From 1312b341a5e1de347c02fc855f80130c1be98cf0 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 16 Oct 2024 07:50:09 +0100 Subject: [PATCH 2/3] use isinstance rather than try --- spinn_utilities/progress_bar.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spinn_utilities/progress_bar.py b/spinn_utilities/progress_bar.py index 7c062bcd..03aab44f 100644 --- a/spinn_utilities/progress_bar.py +++ b/spinn_utilities/progress_bar.py @@ -50,12 +50,10 @@ class ProgressBar(object): def __init__(self, total_number_of_things_to_do: Union[int, Sized], string_describing_what_being_progressed, step_character="=", end_character="|"): - try: - self._number_of_things = int(total_number_of_things_to_do) - except TypeError: - + if isinstance(total_number_of_things_to_do, Sized) self._number_of_things = len(total_number_of_things_to_do) - + else: + self._number_of_things = int(total_number_of_things_to_do) self._currently_completed = 0 self._chars_per_thing = None self._chars_done = 0 From 2b87ee1a8c1124cf56a227233763e3937257dcee Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 16 Oct 2024 07:52:47 +0100 Subject: [PATCH 3/3] oops --- spinn_utilities/progress_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spinn_utilities/progress_bar.py b/spinn_utilities/progress_bar.py index 03aab44f..3364029e 100644 --- a/spinn_utilities/progress_bar.py +++ b/spinn_utilities/progress_bar.py @@ -50,7 +50,7 @@ class ProgressBar(object): def __init__(self, total_number_of_things_to_do: Union[int, Sized], string_describing_what_being_progressed, step_character="=", end_character="|"): - if isinstance(total_number_of_things_to_do, Sized) + if isinstance(total_number_of_things_to_do, Sized): self._number_of_things = len(total_number_of_things_to_do) else: self._number_of_things = int(total_number_of_things_to_do)