Skip to content

Remove the duplicated exception constructors. - #3099

Merged
janiversen merged 2 commits into
pymodbus-dev:devfrom
daveharsh38:refactor/exception-category-pull-up
Nov 25, 2026
Merged

janiversen merged 2 commits into
pymodbus-dev:devfrom
daveharsh38:refactor/exception-category-pull-up

Conversation

@daveharsh38

Copy link
Copy Markdown
Contributor

ParameterException, NoSuchIdException, NotImplementedException, ConnectionException and MessageRegisterException each repeat the same __init__, differing only in the [...] text put in front of the message. This PR moves that constructor into ModbusException, with the text as a class field category that each subclass sets. ModbusIOException uses the same field and keeps its message attribute.

The text, args and str() of every exception are unchanged. I added tests that pin the exact text of each exception, and they pass both before and after the change. check_ci.sh passes with coverage at 100%.

ParameterException, NoSuchIdException, NotImplementedException,
ConnectionException and MessageRegisterException each repeated the same
__init__, differing only in the "[...]" text put in front of the
message. Pull the constructor up into ModbusException, with the text
as a class field "category" that each subclass sets. ModbusIOException
uses the same field and keeps its message attribute. The new tests
pin the exact text of every exception (they pass before and after).

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, Thanks.

Nice cleanup !

@janiversen
janiversen merged commit c5ae7e2 into pymodbus-dev:dev Nov 25, 2026
16 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.

2 participants