Skip to content

Conversation

zariiii9003
Copy link
Contributor

As suggested in #405.

I tried converting OdxLinkRef into a frozen dataclass, but subclasses assign attributes after instantiation.

@zariiii9003
Copy link
Contributor Author

@andlaus Unrelated: i think there are a lot of mypy issues hidden by the Noreturn in the odxraise method. It should be NoReturn | None and the TYPE_CHECKING should be removed.

@andlaus
Copy link
Member

andlaus commented Apr 4, 2025

The Noreturn is on purpose: Semantically odxraise() should be considered identical to raise. The difference is that in non-strict mode it becomes a no-op, i.e. the reason why there is often code after the odxraise() call is to provide a sensible fallback for non-strict mode (which does not make any guarantees about undefined behavior or working in general, just that it "does its best"). So odxraise() should stay Noreturn in the main branch, but for development purposes, it I agree that could be temporarily changed to None to uncover the issues which you mentioned (I suppose that you will get a lot of mypy errors then...)

@andlaus
Copy link
Member

andlaus commented Apr 4, 2025

I tried converting OdxLinkRef into a frozen dataclass, but subclasses assign attributes after instantiation.

IIRC, that was also the issue I stumbled over, ParentRef was particularly bad because it does quite a bit of reference resolution...

@zariiii9003
Copy link
Contributor Author

zariiii9003 commented Apr 4, 2025

A few more changes after a bit of research. To my understanding there are two options: the doc fragments are either just the category, or the category+diag_layer.

i changed the type annotation of OdxDocContext.doc_fragments to reflect that. The category context is now completely defined in Database._process_xml_tree(). The DiagLayerContainer then creates a new context for its layers.

Copy link
Member

@andlaus andlaus left a comment

Choose a reason for hiding this comment

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

looks pretty good. when the match statement is replaced and it is verified that ODX 2.0 does not regress (you might need to help out on that front @kayoub5) I think this should be merged...

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 5, 2025

@nada-ben-ali could you check that odx 2.0 compatibility is not broken with those changes ?

@@ -31,7 +31,7 @@
from .hierarchyelementraw import HierarchyElementRaw

if TYPE_CHECKING:
from .database import Database
from ..database import Database
Copy link
Collaborator

Choose a reason for hiding this comment

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

mypy didn't catch this ?

Copy link
Member

Choose a reason for hiding this comment

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

@zariiii9003: how did you find this? if using tools, can/should we change the CI system to do the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed red squiggly lines in my IDE. I also wonder why both ruff and mypy seem to ignore it

Copy link
Member

Choose a reason for hiding this comment

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

ok. Seems like you should continue to let your IDE look at odxtools. mine (emacs) is not sophisticated enough ;)

@andlaus
Copy link
Member

andlaus commented Apr 7, 2025

sorry for the conflict due to #411. as I see it, the .doc_frags attribute should not be defaulted anyway...

@andlaus
Copy link
Member

andlaus commented Apr 7, 2025

thanks for rebasing. as soon as @nada-ben-ali reports back, I'll merge this.

I don't know why this blew up my smoke testing schript only now...

Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
Signed-off-by: Alexander Walz <alexander.walz@mercedes-benz.com>
@andlaus
Copy link
Member

andlaus commented Apr 10, 2025

For some strange reason, I ran into some DOCREF-related issue with this. I don't know why it only crept up with this PR, but I made a "meta pull request" for your PR here: zariiii9003#1 . would be great if you merged it...

fix DOCREF for PARENT-REFs using implicit document fragments
@andlaus
Copy link
Member

andlaus commented Apr 10, 2025

@nada-ben-ali: were you able to test this with ODX 2.0? I think it is relatively unlikely that it regresses something on that front, and since I get a weird performance regression which goes away with this PR, I'd like to get it merged quickly...

@andlaus
Copy link
Member

andlaus commented Apr 14, 2025

@nada-ben-ali, @kayoub5: If I do not get any objections to this PR, I'll merge it on Thursday...

@nada-ben-ali
Copy link
Collaborator

@zariiii9003 @kayoub5 @andlaus sorryy I've just seen the email notifications. I'll begin checking now.

@nada-ben-ali
Copy link
Collaborator

I got the following exception while loading the pickle file for some pdx files we have:
image

I'm checking this...

@nada-ben-ali
Copy link
Collaborator

I got the following exception while loading the pickle file for some pdx files we have: image

I'm checking this...

the issue is caused by #407.
@kayoub5 @andlaus after removing the changes introduced in #407 and #411 (which have not been included in a release yet), no issues are observed with the current merge request changes.

I'm currently checking the impact of the dataclass as Kw_only on the unpickling operation and how we can fix it. It only occurs with some files, not all of them. For now, I have only identified the MRs that caused the issue.

@andlaus
Copy link
Member

andlaus commented Apr 16, 2025

ok, does this mean that this PR can be merged and I should only prepare the next release once the unpickling issues are fixed? are you on it? (I do not currently use pickling, so I have a hard time reproducing it.)

@nada-ben-ali
Copy link
Collaborator

ok, does this mean that this PR can be merged and I should only prepare the next release once the unpickling issues are fixed? are you on it? (I do not currently use pickling, so I have a hard time reproducing it.)

@andlaus yes, we can merge this, and I'll work on fixing the unpickling problem.

@andlaus
Copy link
Member

andlaus commented Apr 17, 2025

ok, cool. merging; thanks everyone!

@andlaus andlaus merged commit 65c36f5 into mercedes-benz:main Apr 17, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants