diff --git a/odxtools/admindata.py b/odxtools/admindata.py index ec5a6688..eadf9621 100644 --- a/odxtools/admindata.py +++ b/odxtools/admindata.py @@ -66,7 +66,7 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase): @dataclass() class AdminData: language: Optional[str] = None - company_doc_infos: List[CompanyDocInfo] = None + company_doc_infos: List[CompanyDocInfo] = field(default_factory=list) doc_revisions: Optional[List[DocRevision]] = None def _build_odxlinks(self) -> Dict[OdxLinkId, Any]: @@ -120,6 +120,7 @@ def read_admin_data_from_odx(et_element: Optional[ElementTree.Element], revision_label = dr.findtext("REVISION-LABEL") state = dr.findtext("STATE") date = dr.findtext("DATE") + assert date is not None tool = dr.findtext("TOOL") modlist = None diff --git a/odxtools/endofpdufield.py b/odxtools/endofpdufield.py index fff2d10e..5381a75f 100644 --- a/odxtools/endofpdufield.py +++ b/odxtools/endofpdufield.py @@ -88,10 +88,10 @@ def convert_bytes_to_physical(self, decode_state: DecodeState, bit_position: int return value, next_byte_position - def _resolve_references(self, + def _resolve_references(self, # type: ignore[override] parent_dl: "DiagLayer", odxlinks: OdxLinkDatabase) \ - -> None: + -> None: """Recursively resolve any references (odxlinks or sn-refs) """ if self.structure_ref is not None: diff --git a/odxtools/envdata.py b/odxtools/envdata.py index b7371a86..ade2204d 100644 --- a/odxtools/envdata.py +++ b/odxtools/envdata.py @@ -2,7 +2,7 @@ # Copyright (c) 2022 MBition GmbH from dataclasses import dataclass -from typing import Optional, Any, Dict, List +from typing import TYPE_CHECKING, Optional, Any, Dict, List from .parameters import read_parameter_from_odx from .utils import read_description_from_odx @@ -11,6 +11,9 @@ from .parameters.parameterbase import Parameter from .globals import logger +if TYPE_CHECKING: + from .diaglayer import DiagLayer + @dataclass class EnvironmentData(BasicStructure): """This class represents Environment Data that describes the circumstances in which the error occurred.""" @@ -36,10 +39,11 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]: return odxlinks - def _resolve_references(self, + def _resolve_references(self, # type: ignore[override] parent_dl: "DiagLayer", - odxlinks: OdxLinkDatabase) -> None: - odxlinks = super()._resolve_references(parent_dl, odxlinks) + odxlinks: OdxLinkDatabase) \ + -> None: + super()._resolve_references(parent_dl, odxlinks) def __repr__(self) -> str: return ( diff --git a/odxtools/specialdata.py b/odxtools/specialdata.py index 967b69d9..b8add6af 100644 --- a/odxtools/specialdata.py +++ b/odxtools/specialdata.py @@ -56,7 +56,7 @@ def _resolve_references(self, odxlinks: OdxLinkDatabase) -> None: @staticmethod def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) \ - -> SpecialDataGroupCaption: + -> "SpecialData": semantic_info = et_element.get("SI") text_identifier = et_element.get("TI") value = et_element.text or "" @@ -67,16 +67,15 @@ def from_et(et_element: ElementTree.Element, @dataclass class SpecialDataGroup: - _local_sdg_caption: Optional[SpecialDataGroupCaption] - _sdg_caption_ref: Optional[OdxLinkRef] - + sdg_caption: Optional[SpecialDataGroupCaption] + sdg_caption_ref: Optional[OdxLinkRef] semantic_info: Optional[str] # the "SI" attribute values: List[Union["SpecialDataGroup", SpecialData]] @staticmethod def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) \ - -> SpecialDataGroupCaption: + -> "SpecialDataGroup": sdg_caption = None if caption_elem := et_element.find("SDG-CAPTION"): sdg_caption = SpecialDataGroupCaption.from_et(caption_elem, doc_frags) @@ -87,9 +86,9 @@ def from_et(et_element: ElementTree.Element, semantic_info = et_element.get("SI") - values = [] + values: List[Union[SpecialData, SpecialDataGroup]] = [] for value_elem in et_element: - next_entry = None + next_entry: Optional[Union[SpecialData, SpecialDataGroup]] = None if value_elem.tag == "SDG": next_entry = SpecialDataGroup.from_et(value_elem, doc_frags) elif value_elem.tag == "SD": @@ -98,16 +97,16 @@ def from_et(et_element: ElementTree.Element, if next_entry is not None: values.append(next_entry) - return SpecialDataGroup(_local_sdg_caption=sdg_caption, - _sdg_caption_ref=sdg_caption_ref, + return SpecialDataGroup(sdg_caption=sdg_caption, + sdg_caption_ref=sdg_caption_ref, semantic_info=semantic_info, values=values) def _build_odxlinks(self) -> Dict[OdxLinkId, Any]: result = {} - if self._local_sdg_caption is not None: - result.update(self._local_sdg_caption._build_odxlinks()) + if self.sdg_caption is not None: + result.update(self.sdg_caption._build_odxlinks()) for val in self.values: result.update(val._build_odxlinks()) @@ -115,12 +114,10 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]: return result def _resolve_references(self, odxlinks: OdxLinkDatabase) -> None: - if self._sdg_caption_ref is not None: - caption = odxlinks.resolve(self._sdg_caption_ref) + if self.sdg_caption_ref is not None: + caption = odxlinks.resolve(self.sdg_caption_ref) assert isinstance(caption, SpecialDataGroupCaption) self.sdg_caption = caption - else: - self.sdg_caption = self._local_sdg_caption for val in self.values: val._resolve_references(odxlinks) diff --git a/odxtools/structures.py b/odxtools/structures.py index e613e9f6..104555be 100644 --- a/odxtools/structures.py +++ b/odxtools/structures.py @@ -315,9 +315,10 @@ def _build_odxlinks(self): return result - def _resolve_references(self, + def _resolve_references(self, # type: ignore[override] parent_dl: "DiagLayer", - odxlinks: OdxLinkDatabase): + odxlinks: OdxLinkDatabase) \ + -> None: """Recursively resolve any references (odxlinks or sn-refs) """ super()._resolve_references(odxlinks) diff --git a/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 b/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 index 6fec59aa..d9dbe096 100644 --- a/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 +++ b/odxtools/templates/macros/printSingleEcuJob.xml.jinja2 @@ -41,7 +41,6 @@ {%- endif %} {%- endfilter -%} > - {{ peid.printElementID(job)|indent(1) }} {{- psd.printSpecialDataGroups(job.sdgs)|indent(1, first=True) }} {%- if job.functional_class_refs %} diff --git a/odxtools/templates/macros/printSpecialData.xml.jinja2 b/odxtools/templates/macros/printSpecialData.xml.jinja2 index 0e4e470c..8d2071cf 100644 --- a/odxtools/templates/macros/printSpecialData.xml.jinja2 +++ b/odxtools/templates/macros/printSpecialData.xml.jinja2 @@ -29,11 +29,10 @@ SI="{{sdg.semantic_info}}" {%- endif %} {#- -#}> - {%- if sdg._local_sdg_caption %} - {{- printSdgCaption(sdg._local_sdg_caption) | indent(1, first=True) }} - {%- endif %} - {%- if sdg._sdg_caption_ref %} - + {%- if sdg.sdg_caption_ref %} + + {%- elif sdg.sdg_caption %} + {{- printSdgCaption(sdg.sdg_caption) | indent(1, first=True) }} {%- endif %} {%- for sd in sdg.values %} {%- if hasattr(sd, "values") %}