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

Rework host/port and listener setup #1866

Merged
merged 5 commits into from
Oct 31, 2023
Merged

Conversation

alexrudd2
Copy link
Collaborator

@alexrudd2 alexrudd2 commented Oct 27, 2023

The refactored code is less nested, so I hope it is easier to understand.

It also solves a mypy error.

@alexrudd2
Copy link
Collaborator Author

See #1865.

If the test that creates host == socket://__pymodbus_nullmodem:7636 is not valid, this can be simplified further.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

You are touching a very delicate part of the code.

Some of your does not seem correct at a first look,but might very well be correct.

I need a bit of time to review this one.

@janiversen
Copy link
Collaborator

See #1865.

If the test that creates host == socket://__pymodbus_nullmodem:7636 is not valid, this can be simplified further.

That is a valid specification, the definition is "socket://:" for serial port as sockets.

@alexrudd2
Copy link
Collaborator Author

You are touching a very delicate part of the code.

Some of your does not seem correct at a first look,but might very well be correct.

It will remain a secret, how many test failures I had in my attempts 🤣

pymodbus/transport/transport.py Outdated Show resolved Hide resolved
pymodbus/transport/transport.py Outdated Show resolved Hide resolved
janiversen
janiversen previously approved these changes Oct 30, 2023
Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

LGTM.

pymodbus/transport/transport.py Outdated Show resolved Hide resolved
@janiversen janiversen dismissed their stale review October 30, 2023 20:22

Too fast, have to look at the whole PR:

@alexrudd2
Copy link
Collaborator Author

The reason I tried changing things here to was to avoid this inelegant return of None, None.

if self.comm_params.comm_type == CommType.SERIAL:
        host, port = self.init_setup_serial(host, port)
        if not host and not port:
            return

def init_setup_serial(self, host: str, _port: int) -> tuple[str, int]:
...
return None, None

Perhaps you have a cleaner way.

@janiversen
Copy link
Collaborator

The reason I tried changing things here to was to avoid this inelegant return of None, None.

if self.comm_params.comm_type == CommType.SERIAL:
        host, port = self.init_setup_serial(host, port)
        if not host and not port:
            return

def init_setup_serial(self, host: str, _port: int) -> tuple[str, int]:
...
return None, None

Perhaps you have a cleaner way.

Your last change looks ok....but you still have the change with strip and split, which I overlooked when I first approved the PR.

Copy link
Collaborator

@janiversen janiversen left a comment

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 b147aeb into dev Oct 31, 2023
1 check passed
@janiversen janiversen deleted the implicit-optional-transport branch October 31, 2023 08:16
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants