diff --git a/spinn_utilities/conf_loader.py b/spinn_utilities/conf_loader.py index f1391541..aa30827d 100644 --- a/spinn_utilities/conf_loader.py +++ b/spinn_utilities/conf_loader.py @@ -15,7 +15,7 @@ import logging import os -from typing import Callable, Dict, List, Sequence, Tuple, Union +from typing import Callable, Dict, Sequence, Tuple, Union import appdirs from typing_extensions import TypeAlias @@ -30,8 +30,8 @@ def install_cfg_and_error( - filename: str, defaults: List[str], - config_locations: List[str]) -> NoConfigFoundException: + filename: str, defaults: list[str], + config_locations: list[str]) -> NoConfigFoundException: """ Installs a local configuration file based on the templates and raises an exception. @@ -163,7 +163,7 @@ def _read_a_config( configuration.remove_option("Machine", "machine_spec_file") -def _config_locations(filename: str) -> List[str]: +def _config_locations(filename: str) -> list[str]: """ Defines the list of places we can get configuration files from. @@ -185,7 +185,7 @@ def _config_locations(filename: str) -> List[str]: def load_config( - filename: str, defaults: List[str], config_parsers: Union[ + filename: str, defaults: list[str], config_parsers: Union[ Sequence[Tuple[str, _SectionParser]], Dict[str, _SectionParser]] = ()) -> CamelCaseConfigParser: """ diff --git a/spinn_utilities/config_holder.py b/spinn_utilities/config_holder.py index b1d39dbf..3a0192b3 100644 --- a/spinn_utilities/config_holder.py +++ b/spinn_utilities/config_holder.py @@ -16,7 +16,7 @@ from configparser import NoOptionError import logging import os -from typing import Any, Callable, Collection, Dict, List, Optional, Set, Union +from typing import Any, Callable, Collection, Dict, Optional, Set, Union import spinn_utilities.conf_loader as conf_loader from spinn_utilities.configs import CamelCaseConfigParser from spinn_utilities.exceptions import ConfigException @@ -27,7 +27,7 @@ logger = FormatAdapter(logging.getLogger(__file__)) __config: Optional[CamelCaseConfigParser] = None -__default_config_files: List[str] = [] +__default_config_files: list[str] = [] __config_file: Optional[str] = None __unittest_mode: bool = False @@ -174,7 +174,7 @@ def get_config_str_or_none(section, option) -> Optional[str]: def get_config_str_list( - section: str, option: str, token: str = ",") -> List[str]: + section: str, option: str, token: str = ",") -> list[str]: """ Get the string value of a configuration option split into a list. @@ -317,7 +317,7 @@ def has_config_option(section: str, option: str) -> bool: return __config.has_option(section, option) -def config_options(section: str) -> List[str]: +def config_options(section: str) -> list[str]: """ Return a list of option names for the given section name. @@ -328,7 +328,7 @@ def config_options(section: str) -> List[str]: return __config.options(section) -def _check_lines(py_path: str, line: str, lines: List[str], index: int, +def _check_lines(py_path: str, line: str, lines: list[str], index: int, method: Callable[[str, str], Any], used_cfgs: Dict[str, Set[str]], start): """ diff --git a/spinn_utilities/configs/camel_case_config_parser.py b/spinn_utilities/configs/camel_case_config_parser.py index 6d0ef5ee..5827d6c9 100644 --- a/spinn_utilities/configs/camel_case_config_parser.py +++ b/spinn_utilities/configs/camel_case_config_parser.py @@ -13,7 +13,7 @@ # limitations under the License. import configparser -from typing import List, Optional +from typing import Optional NONES = ("none", ) @@ -69,7 +69,7 @@ def get_str(self, section: str, option: str) -> Optional[str]: return value def get_str_list( - self, section: str, option: str, token: str = ",") -> List[str]: + self, section: str, option: str, token: str = ",") -> list[str]: """ Get the string value of an option split into a list. diff --git a/spinn_utilities/data/utils_data_view.py b/spinn_utilities/data/utils_data_view.py index 0791e013..41baf0ee 100644 --- a/spinn_utilities/data/utils_data_view.py +++ b/spinn_utilities/data/utils_data_view.py @@ -13,7 +13,7 @@ # limitations under the License. from __future__ import annotations from tempfile import TemporaryDirectory -from typing import List, Optional +from typing import Optional from unittest import SkipTest from spinn_utilities.exceptions import ( @@ -527,7 +527,7 @@ def get_executable_path(cls, executable_name: str) -> str: executable_name) @classmethod - def get_executable_paths(cls, executable_names: str) -> List[str]: + def get_executable_paths(cls, executable_names: str) -> list[str]: """ Finds each executables within the set of folders. diff --git a/spinn_utilities/executable_finder.py b/spinn_utilities/executable_finder.py index b6d645d2..a6f0a656 100644 --- a/spinn_utilities/executable_finder.py +++ b/spinn_utilities/executable_finder.py @@ -13,7 +13,7 @@ # limitations under the License. import os -from typing import List, Optional +from typing import Optional from spinn_utilities.ordered_set import OrderedSet @@ -105,7 +105,7 @@ def get_executable_path(self, executable_name: str) -> str: raise KeyError(f"Executable {executable_name} not found in paths " f"f{list(self._binary_search_paths)}") - def get_executable_paths(self, executable_names: str) -> List[str]: + def get_executable_paths(self, executable_names: str) -> list[str]: """ Finds each executables within the set of folders. diff --git a/spinn_utilities/log.py b/spinn_utilities/log.py index 26684ada..c6b1f5ce 100644 --- a/spinn_utilities/log.py +++ b/spinn_utilities/log.py @@ -17,7 +17,7 @@ import logging import re import sys -from typing import Any, List, Optional, Tuple +from typing import Any, Optional, Tuple from inspect import getfullargspec from .log_store import LogStore from .overrides import overrides @@ -178,7 +178,7 @@ class FormatAdapter(logging.LoggerAdapter): """ __kill_level = logging.CRITICAL + 1 __repeat_at_end = logging.WARNING - __not_stored_messages: List[Tuple[datetime, int, str]] = [] + __not_stored_messages: list[Tuple[datetime, int, str]] = [] __log_store: Optional[LogStore] = None @classmethod diff --git a/spinn_utilities/log_store.py b/spinn_utilities/log_store.py index 557963ae..53ddf945 100644 --- a/spinn_utilities/log_store.py +++ b/spinn_utilities/log_store.py @@ -13,7 +13,7 @@ # limitations under the License. from datetime import datetime -from typing import List, Optional, Tuple +from typing import Optional, Tuple from .abstract_base import abstractmethod @@ -37,7 +37,7 @@ def store_log(self, level: int, message: str, @abstractmethod def retreive_log_messages( - self, min_level: int = 0) -> List[Tuple[int, str]]: + self, min_level: int = 0) -> list[Tuple[int, str]]: """ Retrieves all log messages at or above the `min_level`. diff --git a/spinn_utilities/progress_bar.py b/spinn_utilities/progress_bar.py index 3b4e3ebe..855f6ec2 100644 --- a/spinn_utilities/progress_bar.py +++ b/spinn_utilities/progress_bar.py @@ -18,7 +18,7 @@ import math import os import sys -from typing import Dict, Iterable, List, TypeVar +from typing import Dict, Iterable, TypeVar from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter from spinn_utilities.overrides import overrides @@ -231,7 +231,7 @@ class _EnhancedProgressBar(ProgressBar): _line_no = 0 _seq_id = 0 - _step_characters: Dict[int, List[str]] = defaultdict(list) + _step_characters: Dict[int, list[str]] = defaultdict(list) _enabled = False _DATA_FILE = "progress_bar.txt" diff --git a/spinn_utilities/ranged/ranged_list.py b/spinn_utilities/ranged/ranged_list.py index 8bb87b7b..be84534f 100644 --- a/spinn_utilities/ranged/ranged_list.py +++ b/spinn_utilities/ranged/ranged_list.py @@ -14,7 +14,7 @@ from __future__ import annotations from collections.abc import Sized from typing import ( - Any, Callable, Generic, List, Iterable, Iterator, Optional, Sequence, + Any, Callable, Generic, Iterable, Iterator, Optional, Sequence, Tuple, Union, cast, final) from typing_extensions import TypeAlias, TypeGuard from spinn_utilities.overrides import overrides @@ -90,7 +90,7 @@ def __init__( self._default: Optional[T] = cast(Optional[T], value) else: self._default = None - self._ranges: Union[List[T], List[_RangeType]] + self._ranges: Union[list[T], list[_RangeType]] self._ranged_based: Optional[bool] = None self.set_value(value, use_list_as_value=use_list_as_value) @@ -106,14 +106,14 @@ def range_based(self) -> bool: return self._ranged_based or False @property - def __the_ranges(self) -> List[_RangeType]: + def __the_ranges(self) -> list[_RangeType]: assert self._ranged_based - return cast(List[_RangeType], self._ranges) + return cast(list[_RangeType], self._ranges) @property - def __the_values(self) -> List[T]: + def __the_values(self) -> list[T]: assert not self._ranged_based - return cast(List[T], self._ranges) + return cast(list[T], self._ranges) @overrides(AbstractList.get_value_by_id) def get_value_by_id(self, the_id: int) -> T: @@ -317,7 +317,7 @@ def listness_check(self, value: _ValueType) -> bool: def as_list( self, value: _ListType, size: int, - ids: Optional[IdsType] = None) -> List[T]: + ids: Optional[IdsType] = None) -> list[T]: """ Converts (if required) the value into a list of a given size. An exception is raised if value cannot be given size elements. diff --git a/spinn_utilities/ranged/ranged_list_of_lists.py b/spinn_utilities/ranged/ranged_list_of_lists.py index 90c03ccb..b45d0722 100644 --- a/spinn_utilities/ranged/ranged_list_of_lists.py +++ b/spinn_utilities/ranged/ranged_list_of_lists.py @@ -14,7 +14,7 @@ from collections.abc import Sized from typing import ( - Callable, Generic, List, Optional, Sequence, TypeVar, Union) + Callable, Generic, Optional, Sequence, TypeVar, Union) from typing_extensions import TypeAlias from spinn_utilities.helpful_functions import is_singleton from spinn_utilities.overrides import overrides @@ -23,10 +23,10 @@ T = TypeVar("T") # ranged_list._ValueType but specialised for how we use it here _ValueType: TypeAlias = Optional[Union[ - List[T], Callable[[int], List[T]], Sequence[List[T]]]] + list[T], Callable[[int], list[T]], Sequence[list[T]]]] -class RangedListOfList(RangedList[List[T]], Generic[T]): +class RangedListOfList(RangedList[list[T]], Generic[T]): """ A Ranged object for lists of list. """ diff --git a/spinn_utilities/typing/json.py b/spinn_utilities/typing/json.py index eadbe518..1987a784 100644 --- a/spinn_utilities/typing/json.py +++ b/spinn_utilities/typing/json.py @@ -16,7 +16,7 @@ Types for JSON. """ -from typing import Dict, List, Union +from typing import Dict, Union from typing_extensions import TypeAlias #: The type of JSON values. @@ -27,7 +27,7 @@ JsonObject: TypeAlias = Dict[str, JsonValue] #: The type of JSON arrays. -JsonArray: TypeAlias = List[JsonValue] +JsonArray: TypeAlias = list[JsonValue] #: The type of JSON arrays of objects. Used for casting. -JsonObjectArray: TypeAlias = List[JsonObject] +JsonObjectArray: TypeAlias = list[JsonObject] diff --git a/unittests/test_log.py b/unittests/test_log.py index 1b4bae1d..de73787c 100644 --- a/unittests/test_log.py +++ b/unittests/test_log.py @@ -14,7 +14,7 @@ from datetime import datetime import logging -from typing import List, Optional, Tuple +from typing import Optional, Tuple from spinn_utilities.log import ( _BraceMessage, ConfiguredFilter, ConfiguredFormatter, FormatAdapter, LogLevelTooHighException) @@ -64,7 +64,7 @@ def store_log(self, level: int, message: str, @overrides(LogStore.retreive_log_messages) def retreive_log_messages( - self, min_level: int = 0) -> List[Tuple[int, str]]: + self, min_level: int = 0) -> list[Tuple[int, str]]: result = [] for (level, message) in self.data: if level >= min_level: diff --git a/unittests/test_overrides.py b/unittests/test_overrides.py index ad6683a8..160813f8 100644 --- a/unittests/test_overrides.py +++ b/unittests/test_overrides.py @@ -13,7 +13,7 @@ # limitations under the License. import pytest -from typing import Any, List +from typing import Any from spinn_utilities.abstract_base import abstractmethod from spinn_utilities.overrides import overrides @@ -24,11 +24,11 @@ class Base(object): - def foo(self, x: int, y: int, z: int) -> List[int]: + def foo(self, x: int, y: int, z: int) -> list[int]: """this is the doc""" return [x, y, z] - def foodef(self, x: Any, y: int, z: Any = True) -> List[Any]: + def foodef(self, x: Any, y: int, z: Any = True) -> list[Any]: """this is the doc""" return [x, y, z] @@ -54,7 +54,7 @@ def bad(self, x: int, y: int, z: int): def test_basic_use(): class Sub(Base): @overrides(Base.foo) - def foo(self, x: int, y: int, z: int) -> List[int]: + def foo(self, x: int, y: int, z: int) -> list[int]: return super().foo(z, y, x) assert Sub().foo(1, 2, 3) == [3, 2, 1] @@ -62,7 +62,7 @@ def foo(self, x: int, y: int, z: int) -> List[int]: def test_doc_no_sub_extend(): class Sub(Base): @overrides(Base.foo, extend_doc=True) - def foo(self, x: int, y: int, z: int) -> List[int]: + def foo(self, x: int, y: int, z: int) -> list[int]: return [z, y, x] assert Sub.foo.__doc__ == "this is the doc" @@ -70,7 +70,7 @@ def foo(self, x: int, y: int, z: int) -> List[int]: def test_doc_no_sub_no_extend(): class Sub(Base): @overrides(Base.foo, extend_doc=False) - def foo(self, x: int, y: int, z: int) -> List[int]: + def foo(self, x: int, y: int, z: int) -> list[int]: return [z, y, x] assert Sub.foo.__doc__ == "this is the doc" @@ -78,7 +78,7 @@ def foo(self, x: int, y: int, z: int) -> List[int]: def test_doc_sub_no_extend(): class Sub(Base): @overrides(Base.foo, extend_doc=False) - def foo(self, x: int, y: int, z: int) -> List[int]: + def foo(self, x: int, y: int, z: int) -> list[int]: """(abc)""" return [z, y, x] assert Sub.foo.__doc__ == "(abc)" @@ -87,7 +87,7 @@ def foo(self, x: int, y: int, z: int) -> List[int]: def test_doc_sub_extend(): class Sub(Base): @overrides(Base.foo, extend_doc=True) - def foo(self, x: int, y: int, z: int) -> List[int]: + def foo(self, x: int, y: int, z: int) -> list[int]: """(abc)""" return [z, y, x] assert Sub.foo.__doc__ == "this is the doc(abc)" @@ -97,7 +97,7 @@ def test_removes_param(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foo) - def foo(self, x: int, y: int) -> List[int]: + def foo(self, x: int, y: int) -> list[int]: return [y, x] assert str(e.value) == WRONG_ARGS.format(3) @@ -106,7 +106,7 @@ def test_adds_param(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foo) - def foo(self, x: int, y: int, z: int, w: int) -> List[int]: + def foo(self, x: int, y: int, z: int, w: int) -> list[int]: return [w, z, y, x] assert str(e.value) == WRONG_ARGS.format(5) @@ -114,7 +114,7 @@ def foo(self, x: int, y: int, z: int, w: int) -> List[int]: def test_adds_expected_param(): class Sub(Base): @overrides(Base.foo, additional_arguments=["w"]) - def foo(self, x: int, y: int, z: int, w: int) -> List[int]: + def foo(self, x: int, y: int, z: int, w: int) -> list[int]: return [w, z, y, x] assert Sub().foo(1, 2, 3, 4) == [4, 3, 2, 1] @@ -123,7 +123,7 @@ def test_renames_param(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foo) - def foo(self, x: int, y: int, w: int) -> List[int]: + def foo(self, x: int, y: int, w: int) -> list[int]: return [w, y, x] assert str(e.value) == "Missing argument z" @@ -132,7 +132,7 @@ def test_renames_param_expected(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foo, additional_arguments=["w"]) - def foo(self, x: int, y: int, w: int) -> List[int]: + def foo(self, x: int, y: int, w: int) -> list[int]: return [w, y, x] assert str(e.value) == WRONG_ARGS.format(4) # TODO: Fix the AWFUL error message in this case! @@ -141,7 +141,7 @@ def foo(self, x: int, y: int, w: int) -> List[int]: def test_changes_params_defaults(): class Sub(Base): @overrides(Base.foodef) - def foodef(self, x: Any, y: Any, z: Any = False) -> List[Any]: + def foodef(self, x: Any, y: Any, z: Any = False) -> list[Any]: return [z, y, x] assert Sub().foodef(1, 2) == [False, 2, 1] @@ -150,7 +150,7 @@ def test_undefaults_super_param(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foodef) - def foodef(self, x: Any, y: Any, z: Any) -> List[Any]: + def foodef(self, x: Any, y: Any, z: Any) -> list[Any]: return [z, y, x] assert str(e.value) == BAD_DEFS @@ -159,7 +159,7 @@ def test_defaults_super_param(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foodef) - def foodef(self, x: Any, y: Any = 1, z: Any = 2) -> List[Any]: + def foodef(self, x: Any, y: Any = 1, z: Any = 2) -> list[Any]: return [z, y, x] assert str(e.value) == BAD_DEFS # TODO: Should this case fail at all? @@ -168,7 +168,7 @@ def foodef(self, x: Any, y: Any = 1, z: Any = 2) -> List[Any]: def test_defaults_super_param_expected(): class Sub(Base): @overrides(Base.foodef, extend_defaults=True) - def foodef(self, x: Any, y: Any = 1, z: Any = 2) -> List[Any]: + def foodef(self, x: Any, y: Any = 1, z: Any = 2) -> list[Any]: return [z, y, x] assert Sub().foodef(7) == [2, 1, 7] @@ -178,7 +178,7 @@ def test_defaults_extra_param(): class Sub(Base): @overrides(Base.foodef, additional_arguments=['pdq']) def foodef(self, x: Any, y: Any, z: Any = 1, pdq: Any = 2 - ) -> List[Any]: + ) -> list[Any]: return [z, y, x, pdq] assert str(e.value) == BAD_DEFS @@ -187,7 +187,7 @@ def test_defaults_super_param_no_super_defaults(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.foo) - def foo(self, x: int, y: int, z: int = 7) -> List[int]: + def foo(self, x: int, y: int, z: int = 7) -> list[int]: return [z, y, x] assert str(e.value) == BAD_DEFS # TODO: Should this case fail at all? @@ -321,7 +321,7 @@ def test_add_return(): with pytest.raises(AttributeError) as e: class Sub(Base): @overrides(Base.bad) - def bad(self, x: int, y: int, z: int) -> List[int]: + def bad(self, x: int, y: int, z: int) -> list[int]: return super().foo(z, y, x) assert str(e.value) == "Super Method bad has no return type, " \ "while this does"