diff --git a/canopen/network.py b/canopen/network.py index 967d804a..dd2a9bcf 100644 --- a/canopen/network.py +++ b/canopen/network.py @@ -279,6 +279,13 @@ def __len__(self) -> int: return len(self.nodes) +class _DummyNetwork(Network): + """Empty network implementation as a placeholder before actual initialization.""" + + def __init__(self, bus: Optional[can.BusABC] = None): + """Do not initialize attributes, by skipping the parent constructor.""" + + class PeriodicMessageTask: """ Task object to transmit a message periodically using python-can's diff --git a/canopen/nmt.py b/canopen/nmt.py index 8ce737ea..4ec7dcca 100644 --- a/canopen/nmt.py +++ b/canopen/nmt.py @@ -2,7 +2,13 @@ import logging import struct import time -from typing import Callable, Optional +from typing import Callable, Optional, TYPE_CHECKING + +from canopen.network import _DummyNetwork + +if TYPE_CHECKING: + from canopen.network import Network + logger = logging.getLogger(__name__) @@ -45,7 +51,7 @@ class NmtBase: def __init__(self, node_id: int): self.id = node_id - self.network = None + self.network: Network = _DummyNetwork() self._state = 0 def on_command(self, can_id, data, timestamp):