Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def __init__(self, name: str, index: int, subindex: int = 0):
#: The value of this variable stored in the object dictionary
self.value: Optional[int] = None
#: Data type according to the standard as an :class:`int`
self.data_type: Optional[int] = None
self.data_type: int = 0
#: Access type, should be "rw", "ro", "wo", or "const"
self.access_type: str = "rw"
#: The variable represents a DOMAIN ObjectType
Expand Down Expand Up @@ -480,7 +480,7 @@ def encode_raw(self, value: Union[int, float, str, bytes, bytearray]) -> bytes:
return self.STRUCT_TYPES[self.data_type].pack(value)
except struct.error:
raise ValueError("Value does not fit in specified type")
elif self.data_type is None:
elif not self.data_type:
raise ObjectDictionaryError("Data type has not been specified")
else:
raise TypeError(
Expand Down
10 changes: 5 additions & 5 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import re
from configparser import NoOptionError, NoSectionError, RawConfigParser
from typing import TYPE_CHECKING
from typing import Any, TYPE_CHECKING

from canopen.objectdictionary import (
ODArray,
Expand Down Expand Up @@ -204,7 +204,7 @@ def import_from_node(node_id: int, network: canopen.network.Network):
return od


def _calc_bit_length(data_type):
def _calc_bit_length(data_type: int) -> int:
if data_type == datatypes.INTEGER8:
return 8
elif data_type == datatypes.INTEGER16:
Expand All @@ -215,7 +215,7 @@ def _calc_bit_length(data_type):
return 64
else:
raise ValueError(
f"Invalid data_type '{data_type}', expecting a signed integer data_type."
f"Invalid data_type 0x{data_type:04X}, expecting an integer data_type."
)


Expand All @@ -229,7 +229,7 @@ def _signed_int_from_hex(hex_str, bit_length):
return number


def _convert_variable(node_id, var_type, value):
def _convert_variable(node_id: int, var_type: int, value: Any) -> Any:
if var_type in (datatypes.OCTET_STRING, datatypes.DOMAIN):
return bytes.fromhex(value)
elif var_type in (datatypes.VISIBLE_STRING, datatypes.UNICODE_STRING):
Expand All @@ -245,7 +245,7 @@ def _convert_variable(node_id, var_type, value):
return int(value, 0)


def _revert_variable(var_type, value):
def _revert_variable(var_type: int, value: Any) -> Any:
if value is None:
return None
if var_type in (datatypes.OCTET_STRING, datatypes.DOMAIN):
Expand Down
Loading