From 78cd30f04b6fd57503911398f69e1c284f7dc092 Mon Sep 17 00:00:00 2001 From: angloth <angus.lothian@hotmail.com> Date: Wed, 8 Apr 2020 22:16:44 +0200 Subject: [PATCH] Add some minor linting changes to port and operation --- b_asic/operation.py | 1 + b_asic/port.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/b_asic/operation.py b/b_asic/operation.py index eeabb2bf..ed327127 100644 --- a/b_asic/operation.py +++ b/b_asic/operation.py @@ -306,5 +306,6 @@ class AbstractOperation(Operation, AbstractGraphComponent): def copy_unconnected(self) -> GraphComponent: new_comp: AbstractOperation = super().copy_unconnected() for name, value in self.params.items(): + new_comp.set_param(name, deepcopy( value)) # pylint: disable=no-member return new_comp diff --git a/b_asic/port.py b/b_asic/port.py index 4f249e3c..103d076a 100644 --- a/b_asic/port.py +++ b/b_asic/port.py @@ -8,6 +8,7 @@ from copy import copy from typing import NewType, Optional, List, Iterable, TYPE_CHECKING from b_asic.signal import Signal +from b_asic.graph_component import Name if TYPE_CHECKING: from b_asic.operation import Operation @@ -144,22 +145,24 @@ class InputPort(AbstractPort): """ return None if self._source_signal is None else self._source_signal.source - def connect(self, src: SignalSourceProvider) -> Signal: + def connect(self, src: SignalSourceProvider, name: Name = "") -> Signal: """Connect the provided signal source to this input port by creating a new signal. Returns the new signal. """ assert self._source_signal is None, "Attempted to connect already connected input port." - return Signal(src.source, self) # self._source_signal is set by the signal constructor. - + # self._source_signal is set by the signal constructor. + return Signal(source=src.source, destination=self, name=name) + @property def value_length(self) -> Optional[int]: """Get the number of bits that this port should truncate received values to.""" return self._value_length - + @value_length.setter def value_length(self, bits: Optional[int]) -> None: """Set the number of bits that this port should truncate received values to.""" - assert bits is None or (isinstance(bits, int) and bits >= 0), "Value length must be non-negative." + assert bits is None or (isinstance( + bits, int) and bits >= 0), "Value length must be non-negative." self._value_length = bits @@ -185,7 +188,7 @@ class OutputPort(AbstractPort, SignalSourceProvider): def add_signal(self, signal: Signal) -> None: assert signal not in self._destination_signals, "Attempted to add already connected signal." self._destination_signals.append(signal) - signal.set_source(self) + signal.set_source(self) def remove_signal(self, signal: Signal) -> None: assert signal in self._destination_signals, "Attempted to remove already removed signal." @@ -195,7 +198,7 @@ class OutputPort(AbstractPort, SignalSourceProvider): def clear(self) -> None: for signal in copy(self._destination_signals): self.remove_signal(signal) - + @property def source(self) -> "OutputPort": - return self \ No newline at end of file + return self -- GitLab