Skip to content
Snippets Groups Projects

Docstring refactor of core

Merged Johannes Kung requested to merge docstring_refactor into main
All threads resolved!
1 file
+ 56
33
Compare changes
  • Side-by-side
  • Inline
+ 56
33
@@ -5,54 +5,77 @@ from typing import Any
class Signal:
"""
Handles datatransportation between modules in the processor.
Each signal has one source module and can have multiple
destination modules.
Signal class to send data between modules in a processor.
Parameters
----------
processor : Processor
Processor that the signal belongs to. Needed to queue processor modules
for update.
name : str
Name of the signal.
value : Any
Initial value of the signal.
"""
def __init__(self, processor: Processor, name: str = "Signal", value = None):
self.processor = processor
self.name = name
self.source = None
self.destinations = set()
self.value = value
def __init__(self, processor: Processor, name: str = "Signal", value=None):
self._processor = processor
self._name = name
self._source = None
self._destinations = set()
self._value = value
def add_destination(self, module: Module) -> None:
"""
Add a destination module that the signal will send new
"""Add a module as a destination that the signal will send new
values to.
"""
self.destinations.add(module)
def set_source(self, module: Module) -> None:
"""
Set source module that will send values through the signal.
"""
self.source = module
self._destinations.add(module)
def update_value(self, value) -> None:
"""
Sets value in signal and queues destination moduels for update.
Set the value of the signal and queue destination modules for update.
Parameters
----------
value : Any
Value to set the signal to.
"""
if value != self.value:
self.value = value
if value != self._value:
self._value = value
# Inform the processor on what modules have been given
# signal so they can update
for destination in self.destinations:
self.processor.add_modules_to_update(destination)
for destination in self._destinations:
self._processor.add_modules_to_update(destination)
def get_value(self) -> Any:
"""
Get the signals current value.
"""
return self.value
"""Get the current value of the signal.
def set_value(self, value) -> None:
Returns
-------
Any
Value of the signal.
"""
Set the value of the signal without queuing the destination
modules of the signal for update. This method should not
be called by a module.
return self._value
def set_value(self, value: Any) -> None:
"""Set the value of the signal without queuing the destination
modules of the signal for update.
This method should not be called by a module.
Parameters
----------
value : any
Value to set the signal to.
"""
self.value = value
self._value = value
def get_name(self) -> str:
return self.name
"""Return the name of the signal.
Returns
-------
str
Name of the signal.
"""
return self._name
Loading