Skip to content

Commit e811a7b

Browse files
authored
[EWB-4549] Generic refactor/tidy up (#193)
Signed-off-by: Max Chesterfield <max.chesterfield@zepben.com>
1 parent b79b2c5 commit e811a7b

3 files changed

Lines changed: 8 additions & 22 deletions

File tree

src/zepben/ewb/services/network/tracing/networktrace/network_trace.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ def visit(self, terminal: Terminal, phases: FrozenSet[SinglePhaseKind]) -> bool:
413413
return self._tracker.visit(terminal, phases)
414414

415415

416-
def default_condition_step_type(step_type: CanActionItem):
417-
if step_type is None:
418-
return False
416+
def default_condition_step_type(step_type: CanActionItem) -> NetworkTraceStep.Type:
419417
if step_type == NetworkTraceActionType.ALL_STEPS:
420418
return NetworkTraceStep.Type.ALL
421419
elif step_type == NetworkTraceActionType.FIRST_STEP_ON_EQUIPMENT:
@@ -432,19 +430,4 @@ def compute_data_with_action_type(compute_data: ComputeData[T], action_type: Can
432430
current_step.data if next_path.traced_internally else compute_data.compute_next(current_step, current_context, next_path)
433431
)
434432
)
435-
raise Exception(f'{action_type.__class__}: step doesnt match expected types')
436-
437-
438-
def with_paths_with_action_type(self, action_type: NetworkTraceActionType) -> ComputeDataWithPaths[T]:
439-
if action_type == NetworkTraceActionType.ALL_STEPS:
440-
return self
441-
elif action_type == NetworkTraceActionType.FIRST_STEP_ON_EQUIPMENT:
442-
return ComputeDataWithPaths(
443-
lambda current_step, current_context, next_path, next_paths: (
444-
current_step.data if next_path.traced_internally else self.compute_next(current_step, current_context, next_path, next_paths)
445-
)
446-
)
447-
raise Exception('step doesnt match expected types')
448-
449-
450-
ComputeDataWithPaths[T].with_action_type = with_paths_with_action_type
433+
raise Exception(f'{action_type.__name__}: step doesnt match expected types')

src/zepben/ewb/services/network/tracing/networktrace/network_trace_action_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# This Source Code Form is subject to the terms of the Mozilla Public
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5-
from typing import Callable, Set, Any
5+
from typing import Callable, FrozenSet, Any
66
from enum import Enum
77

88
from zepben.ewb import Terminal, SinglePhaseKind
99
from zepben.ewb.services.network.tracing.networktrace.network_trace_step import NetworkTraceStep
1010
from zepben.ewb.services.network.tracing.traversal.step_context import StepContext
1111

12-
HasTracked = Callable[[Terminal, Set[SinglePhaseKind]], bool]
12+
HasTracked = Callable[[Terminal, FrozenSet[SinglePhaseKind]], bool]
1313
CanActionItem = Callable[[NetworkTraceStep[Any], StepContext, HasTracked], bool]
1414

1515

src/zepben/ewb/services/network/tracing/networktrace/network_trace_step.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def did_traverse_ac_line_segment(self) -> bool:
9595
def next_num_equipment_steps(self, current_num: int) -> int:
9696
return current_num + 1 if self.traced_externally else current_num
9797

98-
Type = Enum('Type', ('ALL', 'INTERNAL', 'EXTERNAL'))
98+
class Type(Enum):
99+
ALL = 'ALL'
100+
INTERNAL = 'INTERNAL'
101+
EXTERNAL = 'EXTERNAL'
99102

100103
def __init__(self, path: Path, num_terminal_steps: int, num_equipment_steps: int, data: T):
101104
self.path = path

0 commit comments

Comments
 (0)