Skip to content

Commit 4a2e26a

Browse files
authored
Merge pull request #411 from andlaus/defaulted_optional_fields
Specify defaults for all optional dataclass fields
2 parents 8223106 + cb65db5 commit 4a2e26a

File tree

107 files changed

+434
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+434
-430
lines changed

odxtools/admindata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from typing import Any, Optional
44
from xml.etree import ElementTree
55

@@ -12,9 +12,9 @@
1212

1313
@dataclass(kw_only=True)
1414
class AdminData:
15-
language: str | None
16-
company_doc_infos: list[CompanyDocInfo]
17-
doc_revisions: list[DocRevision]
15+
language: str | None = None
16+
company_doc_infos: list[CompanyDocInfo] = field(default_factory=list)
17+
doc_revisions: list[DocRevision] = field(default_factory=list)
1818

1919
@staticmethod
2020
def from_et(et_element: ElementTree.Element | None,

odxtools/audience.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from typing import Any
44
from xml.etree import ElementTree
55

@@ -13,14 +13,14 @@
1313

1414
@dataclass(kw_only=True)
1515
class Audience:
16-
enabled_audience_refs: list[OdxLinkRef]
17-
disabled_audience_refs: list[OdxLinkRef]
18-
19-
is_supplier_raw: bool | None
20-
is_development_raw: bool | None
21-
is_manufacturing_raw: bool | None
22-
is_aftersales_raw: bool | None
23-
is_aftermarket_raw: bool | None
16+
enabled_audience_refs: list[OdxLinkRef] = field(default_factory=list)
17+
disabled_audience_refs: list[OdxLinkRef] = field(default_factory=list)
18+
19+
is_supplier_raw: bool | None = None
20+
is_development_raw: bool | None = None
21+
is_manufacturing_raw: bool | None = None
22+
is_aftersales_raw: bool | None = None
23+
is_aftermarket_raw: bool | None = None
2424

2525
@property
2626
def is_supplier(self) -> bool:

odxtools/basecomparam.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
class BaseComparam(IdentifiableElement):
1818
param_class: str
1919
cptype: StandardizationLevel
20-
display_level: int | None
21-
cpusage: Usage | None # Required in ODX 2.2, missing in ODX 2.0
20+
display_level: int | None = None
21+
cpusage: Usage | None = None # Required in ODX 2.2, missing in ODX 2.0
2222

2323
@staticmethod
2424
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "BaseComparam":

odxtools/basevariantpattern.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from xml.etree import ElementTree
44

55
from typing_extensions import override
@@ -16,7 +16,8 @@ class BaseVariantPattern(VariantPattern):
1616
"""Base variant patterns are variant patterns used to identify the
1717
base variant of an ECU.
1818
"""
19-
matching_base_variant_parameters: list[MatchingBaseVariantParameter]
19+
matching_base_variant_parameters: list[MatchingBaseVariantParameter] = field(
20+
default_factory=list)
2021

2122
@staticmethod
2223
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "BaseVariantPattern":

odxtools/basicstructure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from typing import Any
44
from xml.etree import ElementTree
55

@@ -31,8 +31,8 @@ class BasicStructure(ComplexDop):
3131
data objects. All structure-like objects adhere to the
3232
`CompositeCodec` type protocol.
3333
"""
34-
byte_size: int | None
35-
parameters: NamedItemList[Parameter]
34+
byte_size: int | None = None
35+
parameters: NamedItemList[Parameter] = field(default_factory=NamedItemList)
3636

3737
@property
3838
def required_parameters(self) -> list[Parameter]:

odxtools/commrelation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
@dataclass(kw_only=True)
1919
class CommRelation:
20-
description: Description | None
20+
description: Description | None = None
2121
relation_type: str
22-
diag_comm_ref: OdxLinkRef | None
23-
diag_comm_snref: str | None
24-
in_param_if_snref: str | None
25-
#in_param_if_snpathref: Optional[str] # TODO
26-
out_param_if_snref: str | None
27-
#out_param_if_snpathref: Optional[str] # TODO
28-
value_type_raw: CommRelationValueType | None
22+
diag_comm_ref: OdxLinkRef | None = None
23+
diag_comm_snref: str | None = None
24+
in_param_if_snref: str | None = None
25+
#in_param_if_snpathref: Optional[str] = None # TODO
26+
out_param_if_snref: str | None = None
27+
#out_param_if_snpathref: Optional[str] = None # TODO
28+
value_type_raw: CommRelationValueType | None = None
2929

3030
@property
3131
def diag_comm(self) -> DiagComm:

odxtools/companydata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from typing import Any
44
from xml.etree import ElementTree
55

@@ -16,9 +16,9 @@
1616

1717
@dataclass(kw_only=True)
1818
class CompanyData(IdentifiableElement):
19-
roles: list[str]
20-
team_members: NamedItemList[TeamMember]
21-
company_specific_info: CompanySpecificInfo | None
19+
roles: list[str] = field(default_factory=list)
20+
team_members: NamedItemList[TeamMember] = field(default_factory=NamedItemList)
21+
company_specific_info: CompanySpecificInfo | None = None
2222

2323
@staticmethod
2424
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "CompanyData":

odxtools/companydocinfo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from typing import Any
44
from xml.etree import ElementTree
55

@@ -15,9 +15,9 @@
1515
@dataclass(kw_only=True)
1616
class CompanyDocInfo:
1717
company_data_ref: OdxLinkRef
18-
team_member_ref: OdxLinkRef | None
19-
doc_label: str | None
20-
sdgs: list[SpecialDataGroup]
18+
team_member_ref: OdxLinkRef | None = None
19+
doc_label: str | None = None
20+
sdgs: list[SpecialDataGroup] = field(default_factory=list)
2121

2222
@property
2323
def company_data(self) -> CompanyData:

odxtools/companyrevisioninfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
@dataclass(kw_only=True)
1414
class CompanyRevisionInfo:
1515
company_data_ref: OdxLinkRef
16-
revision_label: str | None
17-
state: str | None
16+
revision_label: str | None = None
17+
state: str | None = None
1818

1919
@property
2020
def company_data(self) -> CompanyData:

odxtools/companyspecificinfo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
from dataclasses import dataclass
2+
from dataclasses import dataclass, field
33
from typing import Any
44
from xml.etree import ElementTree
55

@@ -12,8 +12,8 @@
1212

1313
@dataclass(kw_only=True)
1414
class CompanySpecificInfo:
15-
related_docs: list[RelatedDoc]
16-
sdgs: list[SpecialDataGroup]
15+
related_docs: list[RelatedDoc] = field(default_factory=list)
16+
sdgs: list[SpecialDataGroup] = field(default_factory=list)
1717

1818
@staticmethod
1919
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "CompanySpecificInfo":

0 commit comments

Comments
 (0)