diff --git a/canopen/lss.py b/canopen/lss.py index 7c0b92a6..311f77b5 100644 --- a/canopen/lss.py +++ b/canopen/lss.py @@ -85,7 +85,7 @@ def __init__(self) -> None: self.network: canopen.network.Network = canopen.network._UNINITIALIZED_NETWORK self._node_id = 0 self._data = None - self.responses = queue.Queue() + self.responses: queue.Queue[bytes] = queue.Queue() def send_switch_state_global(self, mode): """switch mode to CONFIGURATION_STATE or WAITING_STATE diff --git a/canopen/node/local.py b/canopen/node/local.py index 886d8ac8..cc1c3d0f 100644 --- a/canopen/node/local.py +++ b/canopen/node/local.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +from collections.abc import Callable from typing import Union import canopen.network @@ -26,8 +27,8 @@ def __init__( super(LocalNode, self).__init__(node_id, object_dictionary) self.data_store: dict[int, dict[int, bytes]] = {} - self._read_callbacks = [] - self._write_callbacks = [] + self._read_callbacks: list[Callable] = [] + self._write_callbacks: list[Callable] = [] self.sdo = SdoServer(0x600 + self.id, 0x580 + self.id, self) self.tpdo = TPDO(self) @@ -62,10 +63,10 @@ def remove_network(self) -> None: self.nmt.network = canopen.network._UNINITIALIZED_NETWORK self.emcy.network = canopen.network._UNINITIALIZED_NETWORK - def add_read_callback(self, callback): + def add_read_callback(self, callback: Callable) -> None: self._read_callbacks.append(callback) - def add_write_callback(self, callback): + def add_write_callback(self, callback: Callable) -> None: self._write_callbacks.append(callback) def get_data( diff --git a/canopen/node/remote.py b/canopen/node/remote.py index 371f784c..01bf8f82 100644 --- a/canopen/node/remote.py +++ b/canopen/node/remote.py @@ -39,7 +39,7 @@ def __init__( #: Enable WORKAROUND for reversed PDO mapping entries self.curtis_hack = False - self.sdo_channels = [] + self.sdo_channels: list[SdoClient] = [] self.sdo = self.add_sdo(0x600 + self.id, 0x580 + self.id) self.tpdo = TPDO(self) self.rpdo = RPDO(self) diff --git a/canopen/objectdictionary/__init__.py b/canopen/objectdictionary/__init__.py index fa694c56..133476e3 100644 --- a/canopen/objectdictionary/__init__.py +++ b/canopen/objectdictionary/__init__.py @@ -207,8 +207,8 @@ def __init__(self, name: str, index: int): self.name = name #: Storage location of index self.storage_location = None - self.subindices = {} - self.names = {} + self.subindices: dict[int, ODVariable] = {} + self.names: dict[str, ODVariable] = {} def __repr__(self) -> str: return f"<{type(self).__qualname__} {self.name!r} at {pretty_index(self.index)}>" @@ -266,8 +266,8 @@ def __init__(self, name: str, index: int): self.name = name #: Storage location of index self.storage_location = None - self.subindices = {} - self.names = {} + self.subindices: dict[int, ODVariable] = {} + self.names: dict[str, ODVariable] = {} def __repr__(self) -> str: return f"<{type(self).__qualname__} {self.name!r} at {pretty_index(self.index)}>" @@ -413,7 +413,7 @@ def add_value_description(self, value: int, descr: str) -> None: """ self.value_descriptions[value] = descr - def add_bit_definition(self, name: str, bits: List[int]) -> None: + def add_bit_definition(self, name: str, bits: list[int]) -> None: """Associate bit(s) with a string description. :param name: Name of bit(s) @@ -508,7 +508,7 @@ def encode_desc(self, desc: str) -> int: raise ValueError( f"No value corresponds to '{desc}'. Valid values are: {valid_values}") - def decode_bits(self, value: int, bits: List[int]) -> int: + def decode_bits(self, value: int, bits: list[int]) -> int: try: bits = self.bit_definitions[bits] except (TypeError, KeyError): @@ -518,7 +518,7 @@ def decode_bits(self, value: int, bits: List[int]) -> int: mask |= 1 << bit return (value & mask) >> min(bits) - def encode_bits(self, original_value: int, bits: List[int], bit_value: int): + def encode_bits(self, original_value: int, bits: list[int], bit_value: int): try: bits = self.bit_definitions[bits] except (TypeError, KeyError): diff --git a/pyproject.toml b/pyproject.toml index e24f6132..73f9914f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,3 +56,7 @@ exclude = [ "^test*", "^setup.py*", ] + +[[tool.mypy.overrides]] +module = ["canmatrix.*"] +ignore_missing_imports = true