Skip to content

Commit 6e56021

Browse files
authored
Merge pull request #1598 from SpiNNakerManchester/pylint4
Pylint4 fixes
2 parents fa282a1 + 52033c3 commit 6e56021

23 files changed

Lines changed: 96 additions & 105 deletions

spynnaker/pyNN/connections/spif_live_spikes_connection.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
from spinn_front_end_common.utilities.database import DatabaseConnection
2525
from spinn_front_end_common.utilities.database import DatabaseReader
2626

27-
_EVENT: Final['TypeAlias'] = Callable[[str, List[int]], None]
28-
_INIT: Final['TypeAlias'] = Callable[[str, int, float, float], None]
29-
_START_STOP: Final['TypeAlias'] = Callable[
27+
Event: Final['TypeAlias'] = Callable[[str, List[int]], None]
28+
Init: Final['TypeAlias'] = Callable[[str, int, float, float], None]
29+
StartStop: Final['TypeAlias'] = Callable[
3030
[str, 'SPIFLiveSpikesConnection'], None]
3131
logger = FormatAdapter(logging.getLogger(__name__))
3232

@@ -119,10 +119,10 @@ def __init__(self, receive_labels: Optional[Iterable[str]],
119119
self.__spif_packet_size = events_per_packet * BYTES_PER_WORD
120120
self.__spif_packet_time_us = time_per_packet
121121
self.__key_to_atom_id_and_label: Dict[int, Tuple[int, int]] = dict()
122-
self.__live_event_callbacks: List[List[Tuple[_EVENT, bool]]] = list()
123-
self.__start_resume_callbacks: Dict[str, List[_START_STOP]] = dict()
124-
self.__pause_stop_callbacks: Dict[str, List[_START_STOP]] = dict()
125-
self.__init_callbacks: Dict[str, List[_INIT]] = dict()
122+
self.__live_event_callbacks: List[List[Tuple[Event, bool]]] = list()
123+
self.__start_resume_callbacks: Dict[str, List[StartStop]] = dict()
124+
self.__pause_stop_callbacks: Dict[str, List[StartStop]] = dict()
125+
self.__init_callbacks: Dict[str, List[Init]] = dict()
126126
if receive_labels is not None:
127127
for label in receive_labels:
128128
self.__live_event_callbacks.append(list())
@@ -147,7 +147,7 @@ def add_receive_label(self, label: str) -> None:
147147
self.__pause_stop_callbacks[label] = list()
148148
self.__init_callbacks[label] = list()
149149

150-
def add_init_callback(self, label: str, init_callback: _INIT) -> None:
150+
def add_init_callback(self, label: str, init_callback: Init) -> None:
151151
"""
152152
Add a callback to be called to initialise a vertex.
153153
@@ -163,7 +163,7 @@ def add_init_callback(self, label: str, init_callback: _INIT) -> None:
163163
self.__init_callbacks[label].append(init_callback)
164164

165165
def add_receive_callback(
166-
self, label: str, live_event_callback: _EVENT,
166+
self, label: str, live_event_callback: Event,
167167
translate_key: bool = True) -> None:
168168
"""
169169
Add a callback for the reception of live events from a vertex.
@@ -185,7 +185,7 @@ def add_receive_callback(
185185
(live_event_callback, translate_key))
186186

187187
def add_start_resume_callback(
188-
self, label: str, start_resume_callback: _START_STOP) -> None:
188+
self, label: str, start_resume_callback: StartStop) -> None:
189189
"""
190190
Add a callback for the start and resume state of the simulation.
191191
@@ -198,7 +198,7 @@ def add_start_resume_callback(
198198
self.__start_resume_callbacks[label].append(start_resume_callback)
199199

200200
def add_pause_stop_callback(
201-
self, label: str, pause_stop_callback: _START_STOP) -> None:
201+
self, label: str, pause_stop_callback: StartStop) -> None:
202202
"""
203203
Add a callback for the pause and stop state of the simulation.
204204
@@ -259,7 +259,7 @@ def __handle_possible_rerun_state(self) -> None:
259259
self.__receiver_connection = None
260260

261261
def __launch_thread(
262-
self, kind: str, label: str, callback: _START_STOP) -> None:
262+
self, kind: str, label: str, callback: StartStop) -> None:
263263
thread = Thread(target=callback, args=(label, self), name=(
264264
f"{kind} callback thread for live_event_connection "
265265
f"{self._local_port}:{self._local_ip_address}"))

spynnaker/pyNN/extra_algorithms/splitter_components/splitter_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
from spynnaker.pyNN.models.neuron.synapse_dynamics import (
2222
AbstractSynapseDynamics, SynapseDynamicsStatic)
2323
from spynnaker.pyNN.models.spike_source import SpikeSourcePoissonVertex
24-
from spynnaker.pyNN.types import DELAYS
24+
from spynnaker.pyNN.types import Delays
2525

2626

2727
def is_direct_poisson_source(
2828
post_vertex: ApplicationVertex, pre_vertex: ApplicationVertex,
2929
connector: AbstractConnector, dynamics: AbstractSynapseDynamics,
30-
delay: DELAYS) -> bool:
30+
delay: Delays) -> bool:
3131
"""
3232
:param post_vertex: The receiving vertex
3333
:param pre_vertex: The vertex sending into the Projection

spynnaker/pyNN/models/neural_projections/connectors/abstract_connector.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from spynnaker.pyNN.data import SpynnakerDataView
4242
from spynnaker.pyNN.types import (
43-
DELAYS, is_scalar, WEIGHTS_DELAYS, WEIGHTS)
43+
Delays, is_scalar, WeightsDelays, Weights)
4444
from spynnaker.pyNN.utilities import utility_calls
4545
from spynnaker.pyNN.exceptions import SpynnakerException
4646

@@ -122,7 +122,7 @@ def set_projection_information(
122122
self.__min_delay = SpynnakerDataView.get_simulation_time_step_ms()
123123

124124
def _get_delay_minimum(
125-
self, delays: DELAYS, n_connections: int,
125+
self, delays: Delays, n_connections: int,
126126
synapse_info: SynapseInformation) -> float:
127127
"""
128128
Get the minimum delay given a float or RandomDistribution.
@@ -147,7 +147,7 @@ def _get_delay_minimum(
147147
raise self.delay_type_exception(delays)
148148

149149
def _get_delay_maximum(
150-
self, delays: DELAYS, n_connections: int,
150+
self, delays: Delays, n_connections: int,
151151
synapse_info: SynapseInformation) -> float:
152152
"""
153153
Get the maximum delay given a float or RandomDistribution.
@@ -187,7 +187,7 @@ def get_delay_minimum(
187187
"""
188188
raise NotImplementedError
189189

190-
def get_delay_variance(self, delays: DELAYS,
190+
def get_delay_variance(self, delays: Delays,
191191
synapse_info: SynapseInformation) -> float:
192192
"""
193193
:param delays:
@@ -204,7 +204,7 @@ def get_delay_variance(self, delays: DELAYS,
204204
raise self.delay_type_exception(delays)
205205

206206
def _get_n_connections_from_pre_vertex_with_delay_maximum(
207-
self, delays: DELAYS, n_total_connections: int,
207+
self, delays: Delays, n_total_connections: int,
208208
n_connections: int, min_delay: float, max_delay: float,
209209
synapse_info: SynapseInformation) -> int:
210210
"""
@@ -278,7 +278,7 @@ def get_n_connections_to_post_vertex_maximum(
278278
"""
279279
raise NotImplementedError
280280

281-
def get_weight_mean(self, weights: WEIGHTS,
281+
def get_weight_mean(self, weights: Weights,
282282
synapse_info: SynapseInformation) -> float:
283283
"""
284284
:param weights:
@@ -295,7 +295,7 @@ def get_weight_mean(self, weights: WEIGHTS,
295295
raise self.weight_type_exception(synapse_info)
296296

297297
def _get_weight_maximum(
298-
self, weights: WEIGHTS, n_connections: int,
298+
self, weights: Weights, n_connections: int,
299299
synapse_info: SynapseInformation) -> float:
300300
"""
301301
Get the maximum of the weights.
@@ -331,7 +331,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
331331
"""
332332
raise NotImplementedError
333333

334-
def get_weight_variance(self, weights: WEIGHTS,
334+
def get_weight_variance(self, weights: Weights,
335335
synapse_info: SynapseInformation) -> float:
336336
"""
337337
:param weights:
@@ -393,7 +393,7 @@ def _generate_random_values(
393393
return copy_rd.next(n_connections)
394394

395395
def _no_space_exception(
396-
self, values: WEIGHTS_DELAYS,
396+
self, values: WeightsDelays,
397397
synapse_info: SynapseInformation) -> SpynnakerException:
398398
"""
399399
:param values:
@@ -407,7 +407,7 @@ def _no_space_exception(
407407
f"{synapse_info.post_population}")
408408

409409
def weight_type_exception(
410-
self, weights: WEIGHTS) -> SpynnakerException:
410+
self, weights: Weights) -> SpynnakerException:
411411
"""
412412
:param weights:
413413
:returns: An Exception explaining incorrect weight or delay type
@@ -430,7 +430,7 @@ def weight_type_exception(
430430
else:
431431
return SpynnakerException(f"Unrecognised weight {weights}")
432432

433-
def delay_type_exception(self, delays: DELAYS) -> SpynnakerException:
433+
def delay_type_exception(self, delays: Delays) -> SpynnakerException:
434434
"""
435435
:param delays:
436436
:returns: An Exception explaining incorrect delay type
@@ -450,7 +450,7 @@ def delay_type_exception(self, delays: DELAYS) -> SpynnakerException:
450450
return SpynnakerException(f"Unrecognised delay {delays}")
451451

452452
def _generate_values(
453-
self, values: WEIGHTS_DELAYS, sources: numpy.ndarray,
453+
self, values: WeightsDelays, sources: numpy.ndarray,
454454
targets: numpy.ndarray, n_connections: int, post_slice: Slice,
455455
synapse_info: SynapseInformation,
456456
weights: bool) -> NDArray[float64]:

spynnaker/pyNN/models/neural_projections/connectors/abstract_generate_connector_on_machine.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from spynnaker.pyNN.models.common.param_generator_data import (
3232
param_generator_params, param_generator_params_size_in_bytes,
3333
param_generator_id, is_param_generatable)
34-
from spynnaker.pyNN.types import (DELAYS, WEIGHTS)
34+
from spynnaker.pyNN.types import (Delays, Weights)
3535
from spynnaker.pyNN.utilities.utility_calls import check_rng
3636

3737
from .abstract_generate_connector_on_host import (
@@ -96,42 +96,42 @@ def generate_on_machine(self, synapse_info: SynapseInformation) -> bool:
9696
check_rng(synapse_info.delays.rng, "RandomDistribution in delay")
9797
return True
9898

99-
def gen_weights_id(self, weights: WEIGHTS) -> int:
99+
def gen_weights_id(self, weights: Weights) -> int:
100100
"""
101101
:param weights:
102102
:returns: The id of the weight generator on the machine.
103103
"""
104104
return param_generator_id(weights)
105105

106-
def gen_weights_params(self, weights: WEIGHTS) -> NDArray[uint32]:
106+
def gen_weights_params(self, weights: Weights) -> NDArray[uint32]:
107107
"""
108108
:param weights:
109109
:returns: The parameters of the weight generator on the machine.
110110
"""
111111
return param_generator_params(weights)
112112

113-
def gen_weight_params_size_in_bytes(self, weights: WEIGHTS) -> int:
113+
def gen_weight_params_size_in_bytes(self, weights: Weights) -> int:
114114
"""
115115
:param weights:
116116
:returns: The size of the weight parameters in bytes.
117117
"""
118118
return param_generator_params_size_in_bytes(weights)
119119

120-
def gen_delays_id(self, delays: DELAYS) -> int:
120+
def gen_delays_id(self, delays: Delays) -> int:
121121
"""
122122
:param delays:
123123
:returns: The id of the delay generator on the machine.
124124
"""
125125
return param_generator_id(delays)
126126

127-
def gen_delay_params(self, delays: DELAYS) -> NDArray[uint32]:
127+
def gen_delay_params(self, delays: Delays) -> NDArray[uint32]:
128128
"""
129129
:param delays:
130130
:returns: The parameters of the delay generator on the machine.
131131
"""
132132
return param_generator_params(delays)
133133

134-
def gen_delay_params_size_in_bytes(self, delays: DELAYS) -> int:
134+
def gen_delay_params_size_in_bytes(self, delays: Delays) -> int:
135135
"""
136136
:param delays:
137137
:returns: The size of the delay parameters in bytes.

spynnaker/pyNN/models/neural_projections/connectors/all_but_me_connector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from spinn_front_end_common.utilities.constants import BYTES_PER_WORD
2626
from spinn_front_end_common.interface.ds import DataType
27-
from spynnaker.pyNN.types import WEIGHTS
27+
from spynnaker.pyNN.types import Weights
2828

2929
from .abstract_connector import AbstractConnector
3030
from .abstract_generate_connector_on_machine import (
@@ -168,7 +168,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
168168
synapse_info)
169169

170170
@overrides(AbstractConnector.get_weight_mean)
171-
def get_weight_mean(self, weights: WEIGHTS,
171+
def get_weight_mean(self, weights: Weights,
172172
synapse_info: SynapseInformation) -> float:
173173
if self.__weights is None:
174174
return AbstractConnector.get_weight_mean(
@@ -177,7 +177,7 @@ def get_weight_mean(self, weights: WEIGHTS,
177177
return float(numpy.mean(numpy.abs(self.__weights)))
178178

179179
@overrides(AbstractConnector.get_weight_variance)
180-
def get_weight_variance(self, weights: WEIGHTS,
180+
def get_weight_variance(self, weights: Weights,
181181
synapse_info: SynapseInformation) -> float:
182182
if self.__weights is None:
183183
return AbstractConnector.get_weight_variance(

spynnaker/pyNN/models/neural_projections/connectors/from_list_connector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from spynnaker.pyNN.data import SpynnakerDataView
3535
from spynnaker.pyNN.exceptions import InvalidParameterType
36-
from spynnaker.pyNN.types import DELAYS, WEIGHTS_DELAYS, WEIGHTS
36+
from spynnaker.pyNN.types import Delays, WeightsDelays, Weights
3737
from .abstract_connector import AbstractConnector
3838
from .abstract_generate_connector_on_host import (
3939
AbstractGenerateConnectorOnHost)
@@ -52,7 +52,7 @@
5252
_FIRST_PARAM = 2
5353

5454

55-
def _is_sequential(value: WEIGHTS_DELAYS
55+
def _is_sequential(value: WeightsDelays
5656
) -> TypeGuard[NDArray[numpy.float64]]:
5757
return isinstance(value, numpy.ndarray)
5858

@@ -151,7 +151,7 @@ def get_delay_minimum(self, synapse_info: SynapseInformation) -> float:
151151
return numpy.min(self.__delays)
152152

153153
@overrides(AbstractConnector.get_delay_variance)
154-
def get_delay_variance(self, delays: DELAYS,
154+
def get_delay_variance(self, delays: Delays,
155155
synapse_info: SynapseInformation) -> float:
156156
if self.__delays is None:
157157
if _is_sequential(synapse_info.delays):
@@ -291,7 +291,7 @@ def get_n_connections_to_post_vertex_maximum(
291291
self.__targets.astype(int64, copy=False))))
292292

293293
@overrides(AbstractConnector.get_weight_mean)
294-
def get_weight_mean(self, weights: WEIGHTS,
294+
def get_weight_mean(self, weights: Weights,
295295
synapse_info: SynapseInformation) -> float:
296296
if self.__weights is None:
297297
if _is_sequential(synapse_info.weights):
@@ -312,7 +312,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
312312
return float(numpy.amax(numpy.abs(self.__weights)))
313313

314314
@overrides(AbstractConnector.get_weight_variance)
315-
def get_weight_variance(self, weights: WEIGHTS,
315+
def get_weight_variance(self, weights: Weights,
316316
synapse_info: SynapseInformation) -> float:
317317
if self.__weights is None:
318318
if _is_sequential(synapse_info.weights):

spynnaker/pyNN/models/neural_projections/connectors/kernel_connector.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from spynnaker.pyNN.exceptions import SpynnakerException
3838
from spynnaker.pyNN.types import (
39-
DELAYS, WEIGHTS_DELAYS, WEIGHTS)
39+
Delays, WeightsDelays, Weights)
4040

4141
from .abstract_connector import AbstractConnector
4242
from .abstract_generate_connector_on_machine import (
@@ -251,7 +251,7 @@ def __pre_as_post(self, pre_r: int, pre_c: int) -> Tuple[int, int]:
251251
return (r, c)
252252

253253
def __get_kernel_vals(self, values: Optional[Union[
254-
_KERNAL, WEIGHTS_DELAYS]]) -> Optional[ConvolutionKernel]:
254+
_KERNAL, WeightsDelays]]) -> Optional[ConvolutionKernel]:
255255
"""
256256
Convert kernel values given into the correct format.
257257
"""
@@ -278,8 +278,8 @@ def __get_kernel_vals(self, values: Optional[Union[
278278
f"{self._kernel_h} and width: {self._kernel_w}).")
279279

280280
def __compute_statistics(
281-
self, weights: Optional[WEIGHTS],
282-
delays: Optional[DELAYS], post_vertex_slice: Slice,
281+
self, weights: Optional[Weights],
282+
delays: Optional[Delays], post_vertex_slice: Slice,
283283
n_pre_neurons: int) -> Tuple[
284284
int, NDArray[uint32], NDArray[uint32], NDArray[floating],
285285
NDArray[floating]]:
@@ -382,7 +382,7 @@ def get_delay_minimum(self, synapse_info: SynapseInformation) -> float:
382382
synapse_info.delays, n_conns, synapse_info)
383383

384384
@overrides(AbstractConnector.get_delay_variance)
385-
def get_delay_variance(self, delays: DELAYS,
385+
def get_delay_variance(self, delays: Delays,
386386
synapse_info: SynapseInformation) -> float:
387387
if self._krn_delays is not None:
388388
return float(numpy.var(self._krn_delays))
@@ -412,15 +412,15 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
412412
synapse_info.weights, n_conns, synapse_info)
413413

414414
@overrides(AbstractConnector.get_weight_mean)
415-
def get_weight_mean(self, weights: WEIGHTS,
415+
def get_weight_mean(self, weights: Weights,
416416
synapse_info: SynapseInformation) -> float:
417417
# Use the kernel weights if user has supplied them
418418
if self._krn_weights is not None:
419419
return float(numpy.mean(self._krn_weights))
420420
return super().get_weight_mean(weights, synapse_info)
421421

422422
@overrides(AbstractConnector.get_weight_variance)
423-
def get_weight_variance(self, weights: WEIGHTS,
423+
def get_weight_variance(self, weights: Weights,
424424
synapse_info: SynapseInformation) -> float:
425425
# Use the kernel weights if user has supplied them
426426
if self._krn_weights is not None:

0 commit comments

Comments
 (0)