Skip to content

Commit

Permalink
Type using list
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Sep 4, 2024
1 parent 0778fe4 commit ea2ef2c
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 57 deletions.
10 changes: 5 additions & 5 deletions spinn_utilities/conf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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:
"""
Expand Down
10 changes: 5 additions & 5 deletions spinn_utilities/config_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/configs/camel_case_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import configparser
from typing import List, Optional
from typing import Optional


NONES = ("none", )
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/data/utils_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/executable_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/log_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
14 changes: 7 additions & 7 deletions spinn_utilities/ranged/ranged_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions spinn_utilities/ranged/ranged_list_of_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
"""
Expand Down
6 changes: 3 additions & 3 deletions spinn_utilities/typing/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
4 changes: 2 additions & 2 deletions unittests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit ea2ef2c

Please sign in to comment.