Skip to content

Make sure any BaseNode always has a valid Node ID#657

Open
acolomb wants to merge 1 commit intocanopen-python:masterfrom
acolomb:node-id-always-valid
Open

Make sure any BaseNode always has a valid Node ID#657
acolomb wants to merge 1 commit intocanopen-python:masterfrom
acolomb:node-id-always-valid

Conversation

@acolomb
Copy link
Copy Markdown
Member

@acolomb acolomb commented May 6, 2026

The BaseNode.id attribute can be initialized either from the given node_id parameter, or from the Object Dictionary if zero was passed. The None value as mentioned in the docstring actually violates the type hint, so drop that suggestion. Make sure the inferred type of the self.id attribute does not allow None, but is always an integer.

Furthermore, check the resulting Node ID against the allowed value range and raise a ValueError instead of constructing a node object with an invalid Node ID, which will cause problems down the road. This is technically an API change, but it just causes things to fail early on instead of raising exceptions later on.

Copy the docstring for LocalNode as well, to document the expected node_id "invalid" value. And because there was none at all before, include a bit of functional description to set the expectations straight.

The BaseNode.id attribute can be initialized either from the given
node_id parameter, or from the Object Dictionary if zero was passed.
The None value as mentioned in the docstring actually violates the
type hint, so drop that suggestion.  Make sure the inferred type of
the self.id attribute does not allow None, but is always an integer.

Furthermore, check the resulting Node ID against the allowed value
range and raise a ValueError instead of constructing a node object
with an invalid Node ID, which will cause problems down the road.
This is technically an API change, but it just causes things to fail
early on instead of raising exceptions later on.

Copy the docstring for LocalNode as well, to document the expected
node_id "invalid" value.  And because there was none at all before,
include a bit of functional description to set the expectations
straight.
@acolomb
Copy link
Copy Markdown
Member Author

acolomb commented May 6, 2026

Replaces #650, as far as Node ID assumptions are concerned.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant