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

Remove superfluous type check to reduce complexity #1510

Merged
merged 2 commits into from
Apr 24, 2023

Conversation

alexrudd2
Copy link
Collaborator

ruff, pylint, and radon all report a McCabe complexity of 11 for this function:

async def handle(self): # pylint: disable=too-complex

There's a conditional to cast slaves to a list if it's an integer:

if not isinstance(slaves, (list, tuple)):
slaves = [slaves]

However, I think this isn't needed since slaves will be setup as a list.

def slaves(self):
"""Define slaves."""
# Python3 now returns keys() as iterable
return list(self._slaves.keys())

Killing this conditional reduces the McCabe complexity from 11 to 10 for both ruff and radon, although pylint still reports it as 11 for some reason >_>. (I've therefore kept the # pylint: disable=too-complex for now. In the future I intend to disable in favor of ruff.)

@alexrudd2
Copy link
Collaborator Author

alexrudd2 commented Apr 24, 2023

I'm not sure why the action for Python3.8 pytest on MacOS is flaky, so I re-ran it. It runs fine for me locally

❯ python3.8 -m pytest .
================================================================= test session starts =================================================================
platform darwin -- Python 3.8.16, pytest-7.2.1, pluggy-1.0.0
rootdir: /Users/a.ruddick/Documents/github/pymodbus, configfile: setup.cfg
plugins: html-2.0.1, asyncio-0.20.3, xdist-3.1.0, timeout-2.1.0, metadata-1.11.0, ordering-0.6, rerunfailures-10.1, cov-4.0.0, seleniumbase-1.65.3, forked-1.3.0
asyncio: mode=auto
gw0 [482] / gw1 [482] / gw2 [482] / gw3 [482] / gw4 [482] / gw5 [482] / gw6 [482] / gw7 [482]
............................................................................................................................................... [ 29%]
............................................................................................................................................... [ 59%]
............................................................................................................................................... [ 88%]
.....................................................                                                                                           [100%]
=========================================================== 482 passed in 75.65s (0:01:15) ============================================================

@janiversen
Copy link
Collaborator

I have the same problem, locally it runs fine. I a. slowly identifying the problem, but until then doing reruns.

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.

Please reinsert the slaves check, otherwise this is ready to go.

pymodbus/server/async_io.py Show resolved Hide resolved
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.

That arguments I cannot counter ! I suppose I know parts of the code better, but that means I often fall into "we normally do" so it is very good, that you question things.

@janiversen janiversen merged commit f9ac901 into dev Apr 24, 2023
@alexrudd2 alexrudd2 deleted the complexity-async-server branch April 24, 2023 20:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 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