Skip to content

Commit

Permalink
Merge pull request #349 from andlaus/fix_papercuts
Browse files Browse the repository at this point in the history
Fix papercuts
  • Loading branch information
andlaus authored Sep 25, 2024
2 parents 2dbcf7a + 809ac72 commit b28fbd1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/somersaultecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,9 +2098,9 @@ class SomersaultSID(IntEnum):
admin_data=None,
data_object_props=NamedItemList(somersault_dops.values()),
unit_spec=UnitSpec(
unit_groups=list(somersault_unit_groups.values()),
units=list(somersault_units.values()),
physical_dimensions=list(somersault_physical_dimensions.values()),
unit_groups=NamedItemList(somersault_unit_groups.values()),
units=NamedItemList(somersault_units.values()),
physical_dimensions=NamedItemList(somersault_physical_dimensions.values()),
sdgs=[],
),
tables=NamedItemList(somersault_tables.values()),
Expand Down
15 changes: 7 additions & 8 deletions odxtools/audience.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from xml.etree import ElementTree

from .additionalaudience import AdditionalAudience
from .nameditemlist import NamedItemList
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef
from .odxtypes import odxstr_to_bool
from .snrefcontext import SnRefContext
Expand Down Expand Up @@ -45,11 +46,11 @@ def is_aftermarket(self) -> bool:
return self.is_aftermarket_raw in [None, True]

@property
def enabled_audiences(self) -> List[AdditionalAudience]:
def enabled_audiences(self) -> NamedItemList[AdditionalAudience]:
return self._enabled_audiences

@property
def disabled_audiences(self) -> List[AdditionalAudience]:
def disabled_audiences(self) -> NamedItemList[AdditionalAudience]:
return self._disabled_audiences

@staticmethod
Expand Down Expand Up @@ -85,12 +86,10 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
return {}

def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
self._enabled_audiences = [
odxlinks.resolve(ref, AdditionalAudience) for ref in self.enabled_audience_refs
]
self._disabled_audiences = [
odxlinks.resolve(ref, AdditionalAudience) for ref in self.disabled_audience_refs
]
self._enabled_audiences = NamedItemList(
[odxlinks.resolve(ref, AdditionalAudience) for ref in self.enabled_audience_refs])
self._disabled_audiences = NamedItemList(
[odxlinks.resolve(ref, AdditionalAudience) for ref in self.disabled_audience_refs])

def _resolve_snrefs(self, context: SnRefContext) -> None:
pass
19 changes: 10 additions & 9 deletions odxtools/unitspec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import Any, Dict, List, Union
from typing import Any, Dict, List
from xml.etree import ElementTree

from .nameditemlist import NamedItemList
Expand All @@ -25,9 +25,9 @@ class UnitSpec:
"""

# TODO (?): Why are there type errors...
unit_groups: Union[NamedItemList[UnitGroup], List[UnitGroup]]
units: Union[NamedItemList[Unit], List[Unit]]
physical_dimensions: Union[NamedItemList[PhysicalDimension], List[PhysicalDimension]]
unit_groups: NamedItemList[UnitGroup]
units: NamedItemList[Unit]
physical_dimensions: NamedItemList[PhysicalDimension]
sdgs: List[SpecialDataGroup]

def __post_init__(self) -> None:
Expand All @@ -38,14 +38,15 @@ def __post_init__(self) -> None:
@staticmethod
def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) -> "UnitSpec":

unit_groups = [
unit_groups = NamedItemList([
UnitGroup.from_et(el, doc_frags) for el in et_element.iterfind("UNIT-GROUPS/UNIT-GROUP")
]
units = [Unit.from_et(el, doc_frags) for el in et_element.iterfind("UNITS/UNIT")]
physical_dimensions = [
])
units = NamedItemList(
[Unit.from_et(el, doc_frags) for el in et_element.iterfind("UNITS/UNIT")])
physical_dimensions = NamedItemList([
PhysicalDimension.from_et(el, doc_frags)
for el in et_element.iterfind("PHYSICAL-DIMENSIONS/PHYSICAL-DIMENSION")
]
])
sdgs = [
SpecialDataGroup.from_et(sdge, doc_frags) for sdge in et_element.iterfind("SDGS/SDG")
]
Expand Down
10 changes: 5 additions & 5 deletions tests/test_unit_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestUnitSpec(unittest.TestCase):

def test_read_odx(self) -> None:
expected = UnitSpec(
physical_dimensions=[
physical_dimensions=NamedItemList([
PhysicalDimension(
odx_id=OdxLinkId("ID.metre", doc_frags),
short_name="metre",
Expand All @@ -45,8 +45,8 @@ def test_read_odx(self) -> None:
long_name=None,
description=None,
)
],
units=[
]),
units=NamedItemList([
Unit(
odx_id=OdxLinkId("ID.kilometre", doc_frags),
oid=None,
Expand All @@ -58,7 +58,7 @@ def test_read_odx(self) -> None:
factor_si_to_unit=1000,
offset_si_to_unit=0,
)
],
]),
unit_groups=NamedItemList(),
sdgs=[],
)
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_resolve_odxlinks(self) -> None:
admin_data=None,
data_object_props=NamedItemList([dop]),
unit_spec=UnitSpec(
units=[unit],
units=NamedItemList([unit]),
physical_dimensions=NamedItemList(),
unit_groups=NamedItemList(),
sdgs=[],
Expand Down

0 comments on commit b28fbd1

Please sign in to comment.