Skip to content

Cleanup ModbusSerialServer.__init__ kwargs#2962

Merged
janiversen merged 7 commits into
pymodbus-dev:devfrom
km-64:cleanup-serial-server-kwargs
Jul 16, 2026
Merged

Cleanup ModbusSerialServer.__init__ kwargs#2962
janiversen merged 7 commits into
pymodbus-dev:devfrom
km-64:cleanup-serial-server-kwargs

Conversation

@km-64

@km-64 km-64 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

ModbusSerialServer's __init__ method describes all kwargs, but some of them are stored in **kwargs. This can be made clearer with type information by giving them explicit types and default values.

Comment thread pymodbus/server/server.py Outdated
Comment thread pymodbus/server/server.py Outdated
@km-64
km-64 marked this pull request as ready for review July 16, 2026 10:47

@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.

Please also update your dev, you are a couple of commits behind.

Comment thread pymodbus/server/server.py Outdated
stopbits: int = 1,
handle_local_echo: bool = False,
allow_multiple_devices: bool = False,
port: str = 0, # type: ignore[assignment]

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.

We try to avoid ignoring type checking !

It is probably hard to find a device that is present on all supported platforms, which could be given as default....so maybe an empty string.

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.

kwargs seems unused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We try to avoid ignoring type checking !

It is probably hard to find a device that is present on all supported platforms, which could be given as default....so maybe an empty string.

There doesn't have to be a default value, it can also be left as just port: str,. If you try calling without passing port it will fail (missing 1 required keyword-only argument: 'port').

That is unless having it fallback to an empty string is useful, but that would probably just raise an exception when pyserial can't open the port

@km-64
km-64 force-pushed the cleanup-serial-server-kwargs branch from f17e2ef to 4de913c Compare July 16, 2026 10:58
Comment thread pymodbus/server/server.py Outdated
@janiversen

janiversen commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Looking at coverage (ubuntu 3.14 in CI), it seems you have introduced a line that is not being tested:

"Required test coverage of 99.95% reached. Total coverage: 99.97%"

Please correct that.

False alarm !!!! this is NOT caused by this PR.

@janiversen

Copy link
Copy Markdown
Collaborator

Please do not misunderstand my review comments !!

I like what you are doing, and all in favor of getting it done....including the other parameter changes you suggested.

BUT when doing it, it should be done correctly, so it is inline with the rest of the code.

btw. I think we have used kwargs as escape goat in several APIs.

@km-64
km-64 requested a review from janiversen July 16, 2026 14:42

@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.

@janiversen
janiversen merged commit 1752aa7 into pymodbus-dev:dev Jul 16, 2026
18 checks passed
@km-64
km-64 deleted the cleanup-serial-server-kwargs branch July 16, 2026 14:45
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