Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comparaminstance.spec property is not available during object creation #392

Merged
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
10 changes: 7 additions & 3 deletions odxtools/comparamsubset.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ class ComparamSubset(OdxCategory):
def from_et(et_element: ElementTree.Element,
doc_frags: List[OdxDocFragment]) -> "ComparamSubset":

cat = OdxCategory.category_from_et(et_element, doc_frags, doc_type=DocType.COMPARAM_SUBSET)
category = et_element.get("CATEGORY")

# In ODX 2.0, COMPARAM-SPEC is used, whereas in ODX 2.2, it refers to something else and has been replaced by COMPARAM-SUBSET.
# - If 'category' is missing (ODX 2.0), use COMPARAM_SPEC,
# - else (ODX 2.2), use COMPARAM_SUBSET.
doc_type = DocType.COMPARAM_SUBSET if category else DocType.COMPARAM_SPEC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small question (now irrelevant because the PR is already merged): isn't it possible to simply look at et_element.tag, i.e.

doc_type = DocType.COMPARAM_SUBSET if et_element.tag == "COMPARAM_SUBSET" else DocType.COMPARAM_SPEC

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yess, it works as well (the tag is "COMPARAM-SUBSET" instead of "COMPARAM_SUBSET").

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supppose that would be less hacky, but I don't mind if you want to leave it as-is...

cat = OdxCategory.category_from_et(et_element, doc_frags, doc_type=doc_type)
doc_frags = cat.odx_id.doc_fragments
kwargs = dataclass_fields_asdict(cat)

category = et_element.get("CATEGORY")

data_object_props = NamedItemList([
DataObjectProperty.from_et(el, doc_frags)
for el in et_element.iterfind("DATA-OBJECT-PROPS/DATA-OBJECT-PROP")
Expand Down