From c8d5fce366cbfc1a1fd2b42ea5204a87020964be Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 27 Nov 2023 17:12:39 +0000 Subject: [PATCH] typing fixes --- pacman/model/graphs/machine/simple_machine_vertex.py | 7 ++++++- pacman/model/resources/constant_sdram.py | 7 ++++--- pacman/model/resources/multi_region_sdram.py | 5 +++-- pacman/model/resources/variable_sdram.py | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pacman/model/graphs/machine/simple_machine_vertex.py b/pacman/model/graphs/machine/simple_machine_vertex.py index ea6434bc9..a780deddc 100644 --- a/pacman/model/graphs/machine/simple_machine_vertex.py +++ b/pacman/model/graphs/machine/simple_machine_vertex.py @@ -12,9 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations +from typing import TYPE_CHECKING from .machine_vertex import MachineVertex from spinn_utilities.overrides import overrides +if TYPE_CHECKING: + from pacman.model.resources import AbstractSDRAM + class SimpleMachineVertex(MachineVertex): """ @@ -41,7 +46,7 @@ def __init__(self, sdram, label=None, @property @overrides(MachineVertex.sdram_required) - def sdram_required(self): + def sdram_required(self) -> AbstractSDRAM: return self._sdram @property diff --git a/pacman/model/resources/constant_sdram.py b/pacman/model/resources/constant_sdram.py index 60373c494..b4394bb9e 100644 --- a/pacman/model/resources/constant_sdram.py +++ b/pacman/model/resources/constant_sdram.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Optional +from typing import Optional, TextIO from spinn_utilities.overrides import overrides from .abstract_sdram import AbstractSDRAM @@ -66,7 +66,7 @@ def __sub__(self, other): return other.sub_from(self) @overrides(AbstractSDRAM.sub_from) - def sub_from(self, other): + def sub_from(self, other: AbstractSDRAM) -> AbstractSDRAM: if isinstance(other, ConstantSDRAM): return ConstantSDRAM( other.fixed - self._sdram) @@ -75,5 +75,6 @@ def sub_from(self, other): return other - self @overrides(AbstractSDRAM.report) - def report(self, timesteps, indent="", preamble="", target=None): + def report(self, timesteps: Optional[int], indent: str = "", + preamble: str = "", target: Optional[TextIO] = None): print(indent, preamble, f"Constant {self._sdram} bytes", file=target) diff --git a/pacman/model/resources/multi_region_sdram.py b/pacman/model/resources/multi_region_sdram.py index 63642d62d..db2d00623 100644 --- a/pacman/model/resources/multi_region_sdram.py +++ b/pacman/model/resources/multi_region_sdram.py @@ -15,7 +15,7 @@ from enum import Enum import math import numpy -from typing import Dict, Union +from typing import Dict, Optional, TextIO, Union from typing_extensions import TypeAlias from spinn_utilities.overrides import overrides from .abstract_sdram import AbstractSDRAM @@ -132,7 +132,8 @@ def merge(self, other: MultiRegionSDRAM): self.__regions[region] = other.regions[region] @overrides(AbstractSDRAM.report) - def report(self, timesteps, indent="", preamble="", target=None): + def report(self, timesteps: Optional[int], indent: str = "", + preamble: str = "", target: Optional[TextIO] = None): super().report(timesteps, indent, preamble, target) for region in self.__regions: self.__regions[region].report( diff --git a/pacman/model/resources/variable_sdram.py b/pacman/model/resources/variable_sdram.py index cbd533810..0d020817b 100644 --- a/pacman/model/resources/variable_sdram.py +++ b/pacman/model/resources/variable_sdram.py @@ -14,7 +14,7 @@ import math import numpy -from typing import Optional, Union +from typing import Optional, TextIO, Union from spinn_utilities.overrides import overrides from pacman.exceptions import PacmanConfigurationException from .abstract_sdram import AbstractSDRAM @@ -87,7 +87,8 @@ def sub_from(self, other: AbstractSDRAM) -> 'VariableSDRAM': other.per_timestep - self._per_timestep_sdram) @overrides(AbstractSDRAM.report) - def report(self, timesteps, indent="", preamble="", target=None): + def report(self, timesteps: Optional[int], indent: str = "", + preamble: str = "", target: Optional[TextIO] = None): print(indent, preamble, f"Fixed {self._fixed_sdram} bytes " f"Per_timestep {self._per_timestep_sdram} bytes "