diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index 08c95261290af1772d4dc9bd75edd09014d57c79..744e37681fddff9c36d9cd35a426637ed4cf5803 100644 --- a/b_asic/core_operations.py +++ b/b_asic/core_operations.py @@ -4,7 +4,7 @@ TODO: More info. """ from b_asic.port import InputPort, OutputPort -from b_asic.operation import OperationId, Operation +from b_asic.operation import Operation from b_asic.basic_operation import BasicOperation from b_asic.graph_id import GraphIDType from numbers import Number @@ -26,7 +26,7 @@ class Constant(BasicOperation): TODO: More info. """ - def __init__(self, identifier: OperationId, value: Number): + def __init__(self, value: Number): """ Construct a Constant. """ @@ -46,11 +46,11 @@ class Addition(BasicOperation): TODO: More info. """ - def __init__(self, identifier: OperationId): + def __init__(self): """ Construct an Addition. """ - super().__init__(identifier) + super().__init__(self) self._input_ports = [InputPort(1), InputPort(1)] # TODO: Generate appropriate ID for ports. self._output_ports = [OutputPort(1)] # TODO: Generate appropriate ID for ports. @@ -67,7 +67,7 @@ class ConstantMultiplication(BasicOperation): TODO: More info. """ - def __init__(self, identifier: OperationId, coefficient: Number): + def __init__(self, coefficient: Number): """ Construct a ConstantMultiplication. """ diff --git a/b_asic/graph_id.py b/b_asic/graph_id.py index fa099d92b3d29c48c56b1b5c9e92bff039f26701..9eba69f5f1a5ddbec1fea7086caec179a683b92d 100644 --- a/b_asic/graph_id.py +++ b/b_asic/graph_id.py @@ -14,7 +14,7 @@ class GraphIDGenerator: A class that generates Graph IDs for objects. """ - _next_id_number: DefaultDict(GraphIDType, GraphIDNumber) + _next_id_number: DefaultDict[GraphIDType, GraphIDNumber] def __init__(self): self._next_id_number = defaultdict(lambda: 1) # Initalises every key element to 1 @@ -46,7 +46,7 @@ class GraphID: def __str__(self) -> str: - return graph_id_type + str(graph_id_number) + return self.graph_id_type + str(self.graph_id_number) def __repr__(self) -> str: @@ -57,12 +57,13 @@ class GraphID: return hash(str(self)) - def __eq__(self, other: GraphID) -> bool: + def __eq__(self, other: object) -> bool: + assert isinstance(other, GraphID), "Other object not an instance of GraphID" return self.graph_id_type == other.graph_id_type and \ self.graph_id_number == other.graph_id_number - def get_next_id(self) -> GraphID: + def get_next_id(self) -> 'GraphID': """ Returns a new GraphID of the same type with an incremented id number. """ diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index c87c4129bde8d6fb51dd0116cd872a8b248a7d1e..cbc29fa2b12a02ad6bfbff1161d7a2c73beca44f 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -7,8 +7,9 @@ from b_asic.operation import Operation from b_asic.basic_operation import BasicOperation from b_asic.signal import Signal, SignalSource, SignalDestination from b_asic.simulation import SimulationState, OperationState +from b_asic.graph_id import GraphIDGenerator, GraphID + from typing import List, Dict, Union -from graph_id import GraphIDGenerator, GraphID class SFG(BasicOperation): @@ -17,7 +18,7 @@ class SFG(BasicOperation): TODO: More info. """ - _graph_objects: Dict(GraphID, Union(Operation, Signal)) + _graph_objects: Dict[GraphID, Union[Operation, Signal]] _graph_id_generator: GraphIDGenerator def __init__(self, input_destinations: List[SignalDestination], output_sources: List[SignalSource]):