diff --git a/canopen/nmt.py b/canopen/nmt.py index 622e0a33..c13d0779 100644 --- a/canopen/nmt.py +++ b/canopen/nmt.py @@ -2,7 +2,7 @@ import struct import threading import time -from typing import Callable, Optional, TYPE_CHECKING +from typing import Callable, Dict, Final, List, Optional, TYPE_CHECKING import canopen.network @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) -NMT_STATES = { +NMT_STATES: Final[Dict[int, str]] = { 0: 'INITIALISING', 4: 'STOPPED', 5: 'OPERATIONAL', @@ -21,7 +21,7 @@ 127: 'PRE-OPERATIONAL' } -NMT_COMMANDS = { +NMT_COMMANDS: Final[Dict[str, int]] = { 'OPERATIONAL': 1, 'STOPPED': 2, 'SLEEP': 80, @@ -32,7 +32,7 @@ 'RESET COMMUNICATION': 130 } -COMMAND_TO_STATE = { +COMMAND_TO_STATE: Final[Dict[int, int]] = { 1: 5, 2: 4, 80: 80, @@ -117,7 +117,7 @@ def __init__(self, node_id: int): #: Timestamp of last heartbeat message self.timestamp: Optional[float] = None self.state_update = threading.Condition() - self._callbacks = [] + self._callbacks: List[Callable[[int], None]] = [] def on_heartbeat(self, can_id, data, timestamp): with self.state_update: @@ -186,7 +186,8 @@ def start_node_guarding(self, period: float): :param period: Period (in seconds) at which the node guarding should be advertised to the slave node. """ - if self._node_guarding_producer : self.stop_node_guarding() + if self._node_guarding_producer: + self.stop_node_guarding() self._node_guarding_producer = self.network.send_periodic(0x700 + self.id, None, period, True) def stop_node_guarding(self): diff --git a/pyproject.toml b/pyproject.toml index e9f3b871..e607aa7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,3 +56,4 @@ exclude = [ "^test*", "^setup.py*", ] +disable_error_code = "annotation-unchecked"