From 6f0e594826255b6bd4b80cd3facced18d6a788cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frieder=20Sch=C3=BCler?= Date: Wed, 29 Apr 2026 21:01:03 +0200 Subject: [PATCH 1/3] Fix too narrow type annotations. --- canopen/emcy.py | 2 +- canopen/network.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/canopen/emcy.py b/canopen/emcy.py index 22d1eba8..6a860f07 100644 --- a/canopen/emcy.py +++ b/canopen/emcy.py @@ -57,7 +57,7 @@ def reset(self): def wait( self, emcy_code: Optional[int] = None, timeout: float = 10 - ) -> EmcyError: + ) -> Optional[EmcyError]: """Wait for a new EMCY to arrive. :param emcy_code: EMCY code to wait for diff --git a/canopen/network.py b/canopen/network.py index 4474c192..0bd56fdf 100644 --- a/canopen/network.py +++ b/canopen/network.py @@ -141,7 +141,7 @@ def add_node( node: Union[int, RemoteNode, LocalNode], object_dictionary: Union[str, ObjectDictionary, None] = None, upload_eds: bool = False, - ) -> RemoteNode: + ) -> Union[RemoteNode, LocalNode]: """Add a remote node to the network. :param node: @@ -167,7 +167,7 @@ def add_node( def create_node( self, - node: int, + node: Union[int, LocalNode], object_dictionary: Union[str, ObjectDictionary, None] = None, ) -> LocalNode: """Create a local node in the network. From 7f9b0cfc27285acd29950a83520b60784feff5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frieder=20Sch=C3=BCler?= Date: Wed, 29 Apr 2026 21:01:03 +0200 Subject: [PATCH 2/3] Return None explicitly. --- canopen/objectdictionary/__init__.py | 1 + canopen/sdo/base.py | 1 + 2 files changed, 2 insertions(+) diff --git a/canopen/objectdictionary/__init__.py b/canopen/objectdictionary/__init__.py index 40ab8fbf..84a89126 100644 --- a/canopen/objectdictionary/__init__.py +++ b/canopen/objectdictionary/__init__.py @@ -188,6 +188,7 @@ def get_variable( return obj elif isinstance(obj, (ODRecord, ODArray)): return obj.get(subindex) + return None class ODRecord(MutableMapping): diff --git a/canopen/sdo/base.py b/canopen/sdo/base.py index 97b0d6c5..d0088ec4 100644 --- a/canopen/sdo/base.py +++ b/canopen/sdo/base.py @@ -79,6 +79,7 @@ def get_variable( return obj elif isinstance(obj, (SdoRecord, SdoArray)): return obj.get(subindex) + return None def upload(self, index: int, subindex: int) -> bytes: raise NotImplementedError() From 1863a96040fbd8224a20afccf8154f7359fe52b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frieder=20Sch=C3=BCler?= Date: Wed, 29 Apr 2026 21:01:03 +0200 Subject: [PATCH 3/3] Annotate ODVariable and ODArray parent attribute as for ODRecord. --- canopen/objectdictionary/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/canopen/objectdictionary/__init__.py b/canopen/objectdictionary/__init__.py index 84a89126..c8de5aa4 100644 --- a/canopen/objectdictionary/__init__.py +++ b/canopen/objectdictionary/__init__.py @@ -262,7 +262,7 @@ class ODArray(Mapping): def __init__(self, name: str, index: int): #: The :class:`~canopen.ObjectDictionary` owning the record. - self.parent = None + self.parent: Optional[ObjectDictionary] = None #: 16-bit address of the array self.index = index #: Name of array @@ -344,7 +344,7 @@ def __init__(self, name: str, index: int, subindex: int = 0): #: The :class:`~canopen.ObjectDictionary`, #: :class:`~canopen.objectdictionary.ODRecord` or #: :class:`~canopen.objectdictionary.ODArray` owning the variable - self.parent = None + self.parent: Union[ObjectDictionary, ODRecord, ODArray, None] = None #: 16-bit address of the object in the dictionary self.index = index #: 8-bit sub-index of the object in the dictionary