Skip to content

Commit

Permalink
typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Oct 16, 2024
1 parent b499c49 commit f860dbc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion spinn_utilities/configs/camel_case_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self) -> None:
self._read_files: List[str] = list()

def read(self, filenames: _Path,
encoding: Optional[str] = None):
encoding: Optional[str] = None) -> List[str]:
"""
Read and parse a filename or a list of filenames.
"""
Expand Down
14 changes: 7 additions & 7 deletions spinn_utilities/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ class Ping(object):
unreachable: Set[str] = set()

@staticmethod
def ping(ip_address):
def ping(ip_address: str) -> int:
"""
Send a ping (ICMP ECHO request) to the given host.
SpiNNaker boards support ICMP ECHO when booted.
:param str ip_address:
:param ip_address:
The IP address to ping. Hostnames can be used, but are not
recommended.
:return:
return code of subprocess; 0 for success, anything else for failure
:rtype: int
"""
if platform.platform().lower().startswith("windows"):
cmd = "ping -n 1 -w 1 "
Expand All @@ -46,23 +45,24 @@ def ping(ip_address):
process = subprocess.Popen(
cmd + ip_address, shell=True, stdout=subprocess.PIPE)
time.sleep(1.2)
process.stdout.close()
_stdout = process.stdout
assert _stdout is not None
_stdout.close()
process.wait()
return process.returncode

@staticmethod
def host_is_reachable(ip_address):
def host_is_reachable(ip_address: str) -> bool:
"""
Test if a host is unreachable via ICMP ECHO.
.. note::
This information may be cached in various ways. Transient failures
are not necessarily detected or recovered from.
:param str ip_address:
:param ip_address:
The IP address to ping. Hostnames can be used, but are not
recommended.
:rtype: bool
"""
if ip_address in Ping.unreachable:
return False
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/ranged/abstract_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def ids(self) -> Sequence[int]:
raise NotImplementedError

@overload
def iter_all_values(self, key: str, update_safe=False) -> Iterator[T]:
def iter_all_values(self, key: str, update_safe: bool = False) -> Iterator[T]:
...

@overload
Expand Down Expand Up @@ -331,7 +331,7 @@ def has_key(self, key: str) -> bool:
"""
return key in self.keys()

def reset(self, key: str):
def reset(self, key: str) -> None:
"""
Sets the value(s) for a single key back to the default value.
Expand Down
4 changes: 3 additions & 1 deletion spinn_utilities/ranged/multiple_values_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Optional


class MultipleValuesException(Exception):
"""
Raised when there more than one value found unexpectedly.
"""

def __init__(self, key, value1, value2):
def __init__(self, key: Optional[str], value1: Any, value2: Any):
if key is None:
msg = "Multiple values found"
else:
Expand Down
4 changes: 2 additions & 2 deletions spinn_utilities/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
from datetime import timedelta
from time import perf_counter_ns
from typing import Optional
from typing import Any, Optional, Tuple
from typing_extensions import Literal

# conversion factor
Expand Down Expand Up @@ -75,7 +75,7 @@ def __enter__(self) -> 'Timer':
self.start_timing()
return self

def __exit__(self, *_args) -> Literal[False]:
def __exit__(self, *_args: Tuple[Any, ...]) -> Literal[False]:
self._measured_section_interval = self.take_sample()
return False

Expand Down

0 comments on commit f860dbc

Please sign in to comment.