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

slightly refactor the length key code #161

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

andlaus
Copy link
Collaborator

@andlaus andlaus commented Jul 17, 2023

now, instead of using hacks with ODXLINK IDs, proper references to LengthKeyParameter are used by ParamLengthInfoType. This necessitates to include the diag coded types in the reference resolution machinery because ParamLengthInfoType is a diag coded type and it needs to resolve the reference to the length key parameter.

Andreas Lauser <[email protected]>, on behalf of MBition GmbH.
Provider Information

now, instead of using hacks with ODXLINK IDs, proper references to
`LengthKeyParameter` are used by `ParamLengthInfoType`. This
necessitates to include the diag coded types in the reference
resolution machinery because `ParamLengthInfoType` is a diag coded
type and it needs to resolve the reference to the length key
parameter.

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Gerrit Ecke <[email protected]>
@andlaus andlaus requested a review from kayoub5 July 17, 2023 07:55
@@ -478,11 +493,28 @@ def __init__(
base_type_encoding=base_type_encoding,
is_highlow_byte_order_raw=is_highlow_byte_order_raw,
)
self.length_key_id = length_key_id
self.length_key_ref = length_key_ref
Copy link
Collaborator

@kayoub5 kayoub5 Jul 17, 2023

Choose a reason for hiding this comment

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

small breaking change, bump major again?

Copy link
Collaborator Author

@andlaus andlaus Jul 17, 2023

Choose a reason for hiding this comment

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

in principle its a breaking change, but I'm willing to bet a box of Champaign that nobody outside of this repository ever used this attribute...

@@ -519,14 +551,14 @@ def convert_bytes_to_internal(self, decode_state: DecodeState, bit_position: int
# if isinstance(param_value.parameter, LengthKeyParameter) would be prettier,
# but leads to cyclic import...
if (parameter.parameter_type == "LENGTH-KEY" and
parameter.odx_id == self.length_key_id # type: ignore
parameter.odx_id == self.length_key.odx_id # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

type ignore still needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unfortunately it is still required:

> mypy --ignore-missing-imports odxtools examples/ tests/
odxtools/diagcodedtypes.py:554: error: "Parameter" has no attribute "odx_id"  [attr-defined]
Found 1 error in 1 file (checked 110 source files)

this is due to the fact that the base class for parameters does not exhibit an ID. (only some do, amongst them LengthKeyParameter.)

We should only ignore the attr-defined error here though. Fixed, thanks!

):
# The bit length of the parameter to be extracted is given by the length key.
assert isinstance(value, int)
bit_length = value
break

assert bit_length is not None, f"Did not find any length key with ID {self.length_key_id}"
assert bit_length is not None, f"Did not find any length key with ID {self.length_key.odx_id}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

raise odx exception instead of assert

Copy link
Collaborator Author

@andlaus andlaus Jul 17, 2023

Choose a reason for hiding this comment

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

I'd prefer not to open this can of worm in this PR. (I guess I should do the assert -> odxassert() conversion soon.)

The praise goes to [at]kayoub5, all remaining bugs are my own fault!

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Gerrit Ecke <[email protected]>
@andlaus andlaus merged commit d522e7a into mercedes-benz:main Jul 17, 2023
6 checks passed
@andlaus andlaus deleted the refactor_length_keys branch December 7, 2023 13:30
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.

2 participants