From de32194f8681f00056ac23bf77ca1c90db0dc729 Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Thu, 20 Jul 2023 23:00:21 -0500 Subject: [PATCH 1/2] Upgrade ruff --- .pre-commit-config.yaml | 2 +- requirements.txt | 2 +- ruff.toml | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ae198d03..c9cedd558 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: check-added-large-files # run ruff with --fix before black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.263' + rev: 'v0.0.277' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/requirements.txt b/requirements.txt index 57f6b78da..169c65aee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -59,7 +59,7 @@ pytest-asyncio>=0.20.3 pytest-cov>=4.1.0 pytest-timeout>=2.1.0 pytest-xdist>=3.3.1 -ruff>=0.0.261 +ruff>=0.0.277 types-Pygments types-pyserial twine>=4.0.2 diff --git a/ruff.toml b/ruff.toml index 75cd36afe..d6ad6496a 100644 --- a/ruff.toml +++ b/ruff.toml @@ -15,6 +15,8 @@ ignore = [ "S101", # Use of `assert` "S311", # PRNG for cryptography "S104", # binding on all interfaces + "RUF012", # typing.ClassVar + "RUF013", # implicit Optional ] line-length = 120 select = [ From a8f2051bbe04f8d75cb2d427120568831abbb3b8 Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Thu, 20 Jul 2023 23:00:33 -0500 Subject: [PATCH 2/2] Remove unnecessary string cast --- examples/client_calls.py | 4 ++-- examples/server_updating.py | 2 +- pymodbus/client/base.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/client_calls.py b/examples/client_calls.py index a5115903f..7b8648013 100755 --- a/examples/client_calls.py +++ b/examples/client_calls.py @@ -79,7 +79,7 @@ async def async_template_call(client): raise ModbusException(txt) # Validate data - txt = f"### Template coils response: {str(rr.bits)}" + txt = f"### Template coils response: {rr.bits!s}" _logger.debug(txt) @@ -102,7 +102,7 @@ def template_call(client): raise ModbusException(txt) # Validate data - txt = f"### Template coils response: {str(rr.bits)}" + txt = f"### Template coils response: {rr.bits!s}" _logger.debug(txt) diff --git a/examples/server_updating.py b/examples/server_updating.py index f7ff0de35..0d2b5f24d 100755 --- a/examples/server_updating.py +++ b/examples/server_updating.py @@ -52,7 +52,7 @@ async def updating_task(context): address = 0x10 values = context[slave_id].getValues(fc_as_hex, address, count=5) values = [v + 1 for v in values] # increment by 1. - txt = f"new values: {str(values)}" + txt = f"new values: {values!s}" _logger.debug(txt) context[slave_id].setValues(fc_as_hex, address, values) await asyncio.sleep(1) diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 75d6c0878..578be12b2 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -176,10 +176,10 @@ def execute(self, request: ModbusRequest = None) -> ModbusResponse: """ if self.use_sync: if not self.connected: - raise ConnectionException(f"Failed to connect[{str(self)}]") + raise ConnectionException(f"Failed to connect[{self!s}]") return self.transaction.execute(request) if not self.transport: - raise ConnectionException(f"Not connected[{str(self)}]") + raise ConnectionException(f"Not connected[{self!s}]") return self.async_execute(request) # ----------------------------------------------------------------------- #