Skip to content

Commit f4dd48e

Browse files
committed
network: Fix type hint for CAN message data.
Use the CanData type alias provided by python-can to properly describe the accepted types for message data. This better matches the parameter description in the docstring, which specifically does *not* require a bytes-like object.
1 parent b20d30b commit f4dd48e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

canopen/network.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Callable, Final, Optional, Union
77

88
import can
9+
from can.typechecking import CanData
910

1011
from canopen.lss import LssMaster
1112
from canopen.nmt import NmtMaster
@@ -187,7 +188,7 @@ def create_node(
187188
self[node.id] = node
188189
return node
189190

190-
def send_message(self, can_id: int, data: bytes, remote: bool = False) -> None:
191+
def send_message(self, can_id: int, data: Optional[CanData], remote: bool = False) -> None:
191192
"""Send a raw CAN message to the network.
192193
193194
This method may be overridden in a subclass if you need to integrate
@@ -215,7 +216,7 @@ def send_message(self, can_id: int, data: bytes, remote: bool = False) -> None:
215216
self.check()
216217

217218
def send_periodic(
218-
self, can_id: int, data: bytes, period: float, remote: bool = False
219+
self, can_id: int, data: Optional[CanData], period: float, remote: bool = False
219220
) -> PeriodicMessageTask:
220221
"""Start sending a message periodically.
221222
@@ -310,7 +311,7 @@ class PeriodicMessageTask:
310311
def __init__(
311312
self,
312313
can_id: int,
313-
data: bytes,
314+
data: Optional[CanData],
314315
period: float,
315316
bus,
316317
remote: bool = False,
@@ -339,7 +340,7 @@ def stop(self):
339340
"""Stop transmission"""
340341
self._task.stop()
341342

342-
def update(self, data: bytes) -> None:
343+
def update(self, data: CanData) -> None:
343344
"""Update data of message
344345
345346
:param data:

0 commit comments

Comments
 (0)