diff --git a/odxtools/dynamicendmarkerfield.py b/odxtools/dynamicendmarkerfield.py index a85bb328..5e31aada 100644 --- a/odxtools/dynamicendmarkerfield.py +++ b/odxtools/dynamicendmarkerfield.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, Any, Dict, List, Sequence from xml.etree import ElementTree from typing_extensions import override @@ -65,7 +65,7 @@ def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeSt odxassert(encode_state.cursor_bit_position == 0, "No bit position can be specified for dynamic endmarker fields!") - if not isinstance(physical_value, (tuple, list)): + if not isinstance(physical_value, Sequence): odxraise( f"Expected a sequence of values for dynamic endmarker field {self.short_name}, " f"got {type(physical_value).__name__}", EncodeError) diff --git a/odxtools/dynamiclengthfield.py b/odxtools/dynamiclengthfield.py index dc64f36b..bff0889a 100644 --- a/odxtools/dynamiclengthfield.py +++ b/odxtools/dynamiclengthfield.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, Any, Dict, List, Sequence from xml.etree import ElementTree from typing_extensions import override @@ -55,7 +55,7 @@ def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeSt odxassert(encode_state.cursor_bit_position == 0, "No bit position can be specified for dynamic length fields!") - if not isinstance(physical_value, (tuple, list)): + if not isinstance(physical_value, Sequence): odxraise( f"Expected a list of values for dynamic length field {self.short_name}, " f"got {type(physical_value)}", EncodeError) diff --git a/odxtools/endofpdufield.py b/odxtools/endofpdufield.py index 8515bd26..53d6a7ef 100644 --- a/odxtools/endofpdufield.py +++ b/odxtools/endofpdufield.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT from dataclasses import dataclass -from typing import List, Optional +from typing import List, Optional, Sequence from xml.etree import ElementTree from typing_extensions import override @@ -49,7 +49,7 @@ def encode_into_pdu(self, physical_value: Optional[ParameterValue], odxassert(encode_state.is_end_of_pdu, "End-of-pdu fields can only be located at the end of PDUs!") - if not isinstance(physical_value, (tuple, list)): + if not isinstance(physical_value, Sequence): odxraise( f"Invalid type {type(physical_value).__name__} of physical " f"value for end-of-pdu field, expected a list", EncodeError) diff --git a/odxtools/odxtypes.py b/odxtools/odxtypes.py index a8baad6c..7158b90c 100644 --- a/odxtools/odxtypes.py +++ b/odxtools/odxtypes.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: MIT from enum import Enum -from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type, Union, overload +from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterable, Optional, Tuple, Type, Union, + overload) from xml.etree import ElementTree from .exceptions import odxassert, odxraise, odxrequire @@ -28,7 +29,7 @@ def bytefield_to_bytearray(bytefield: str) -> bytearray: # multiple items, so this can be a list of objects. TableStructParameterValue = Tuple[str, "ParameterValue"] ParameterValue = Union[AtomicOdxType, "ParameterValueDict", TableStructParameterValue, - List["ParameterValue"], "DiagnosticTroubleCode"] + Iterable["ParameterValue"], "DiagnosticTroubleCode"] ParameterValueDict = Dict[str, ParameterValue] diff --git a/odxtools/staticfield.py b/odxtools/staticfield.py index 0f75bb8a..76069f65 100644 --- a/odxtools/staticfield.py +++ b/odxtools/staticfield.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Dict, List +from typing import TYPE_CHECKING, Any, Dict, List, Sequence from xml.etree import ElementTree from typing_extensions import override @@ -51,7 +51,7 @@ def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None: def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeState) -> None: if not isinstance(physical_value, - (tuple, list)) or len(physical_value) != self.fixed_number_of_items: + Sequence) or len(physical_value) != self.fixed_number_of_items: odxraise(f"Value for static field '{self.short_name}' " f"must be a list of size {self.fixed_number_of_items}")