diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b5d35cb10..98611b965 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -12,12 +12,12 @@ repos: - id: check-added-large-files # run ruff with --fix before black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.261' + rev: 'v0.0.263' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.3.0 hooks: - id: black args: [--safe, --quiet] diff --git a/examples/build_bcd_payload.py b/examples/build_bcd_payload.py index 67a626f01..0479a6e4a 100644 --- a/examples/build_bcd_payload.py +++ b/examples/build_bcd_payload.py @@ -98,10 +98,10 @@ def build(self): """ string = str(self) length = len(string) - string = string + ("\x00" * (length % 2)) + string += "\x00" * (length % 2) return [string[i : i + 2] for i in range(0, length, 2)] - def add_bits(self, values: int) -> int: + def add_bits(self, values: int) -> None: """Add a collection of bits to be encoded If these are less than a multiple of eight, diff --git a/examples/message_parser.py b/examples/message_parser.py index cfd764206..f24ee4bd0 100755 --- a/examples/message_parser.py +++ b/examples/message_parser.py @@ -106,7 +106,7 @@ def report(self, message): message.__class__.__name__, ) ) - for (k_dict, v_dict) in message.__dict__.items(): + for k_dict, v_dict in message.__dict__.items(): if isinstance(v_dict, dict): print("%-15s =" % k_dict) # pylint: disable=consider-using-f-string for k_item, v_item in v_dict.items(): diff --git a/pymodbus/client/serial_asyncio/__init__.py b/pymodbus/client/serial_asyncio/__init__.py index 7437a47fa..beb3271c5 100644 --- a/pymodbus/client/serial_asyncio/__init__.py +++ b/pymodbus/client/serial_asyncio/__init__.py @@ -425,7 +425,7 @@ def _call_connection_lost(self, exc): if self._serial: try: self._serial.flush() - except (serial.SerialException if os.name == "nt" else termios.error): + except serial.SerialException if os.name == "nt" else termios.error: # ignore serial errors which may happen if the serial device was # hot-unplugged. pass diff --git a/pymodbus/client/sync_diag.py b/pymodbus/client/sync_diag.py index 19e422f5a..63ad2a890 100644 --- a/pymodbus/client/sync_diag.py +++ b/pymodbus/client/sync_diag.py @@ -84,7 +84,7 @@ def __init__( self.warn_delay_limit = self.params.timeout / 2 # Set logging messages, defaulting to LOG_MSGS - for (k_item, v_item) in LOG_MSGS.items(): + for k_item, v_item in LOG_MSGS.items(): self.__dict__[k_item] = kwargs.get(k_item, v_item) def connect(self): diff --git a/pymodbus/datastore/context.py b/pymodbus/datastore/context.py index a6e11a592..0462ab984 100644 --- a/pymodbus/datastore/context.py +++ b/pymodbus/datastore/context.py @@ -76,7 +76,7 @@ def validate(self, fc_as_hex, address, count=1): :returns: True if the request in within range, False otherwise """ if not self.zero_mode: - address = address + 1 + address += 1 Log.debug("validate: fc-[{}] address-{}: count-{}", fc_as_hex, address, count) return self.store[self.decode(fc_as_hex)].validate(address, count) @@ -89,7 +89,7 @@ def getValues(self, fc_as_hex, address, count=1): :returns: The requested values from a:a+c """ if not self.zero_mode: - address = address + 1 + address += 1 Log.debug("getValues: fc-[{}] address-{}: count-{}", fc_as_hex, address, count) return self.store[self.decode(fc_as_hex)].getValues(address, count) @@ -101,7 +101,7 @@ def setValues(self, fc_as_hex, address, values): :param values: The new values to be set """ if not self.zero_mode: - address = address + 1 + address += 1 Log.debug("setValues[{}] address-{}: count-{}", fc_as_hex, address, len(values)) self.store[self.decode(fc_as_hex)].setValues(address, values) diff --git a/pymodbus/diag_message.py b/pymodbus/diag_message.py index 459189ad2..82498a154 100644 --- a/pymodbus/diag_message.py +++ b/pymodbus/diag_message.py @@ -161,7 +161,7 @@ def decode(self, data): word_len = len(data) // 2 if len(data) % 2: word_len += 1 - data = data + b"0" + data += b"0" data = struct.unpack(">" + "H" * word_len, data) ( self.sub_function_code, # pylint: disable=attribute-defined-outside-init diff --git a/pymodbus/mei_message.py b/pymodbus/mei_message.py index 06151f1ae..5a1a6b1db 100644 --- a/pymodbus/mei_message.py +++ b/pymodbus/mei_message.py @@ -170,7 +170,7 @@ def encode(self): self.space_left = 253 - 6 objects = b"" try: - for (object_id, data) in iter(self.information.items()): + for object_id, data in iter(self.information.items()): if isinstance(data, list): for item in data: objects += self._encode_object(object_id, item) diff --git a/pymodbus/other_message.py b/pymodbus/other_message.py index 7f266080c..ae96950c0 100644 --- a/pymodbus/other_message.py +++ b/pymodbus/other_message.py @@ -475,13 +475,9 @@ def decode(self, data): status = int(data[-1]) self.status = status == ModbusStatus.SlaveOn - def __str__(self): + def __str__(self) -> str: """Build a representation of the response. :returns: The string representation of the response """ - arguments = (self.function_code, self.identifier, self.status) - return ( - "ReportSlaveIdResponse(%s, %s, %s)" # pylint: disable=consider-using-f-string - % arguments - ) + return f"ReportSlaveIdResponse({self.function_code}, {self.identifier}, {self.status})" diff --git a/pymodbus/payload.py b/pymodbus/payload.py index 624915309..00439cbc1 100644 --- a/pymodbus/payload.py +++ b/pymodbus/payload.py @@ -133,7 +133,7 @@ def build(self): """ string = self.to_string() length = len(string) - string = string + (b"\x00" * (length % 2)) + string += b"\x00" * (length % 2) return [string[i : i + 2] for i in range(0, length, 2)] def add_bits(self, values): diff --git a/pymodbus/repl/client/main.py b/pymodbus/repl/client/main.py index e231b1dc9..27341607e 100644 --- a/pymodbus/repl/client/main.py +++ b/pymodbus/repl/client/main.py @@ -95,11 +95,7 @@ def convert(self, value, param, ctx): return choice self.fail( - "invalid choice: %s. (choose from %s)" # pylint: disable=consider-using-f-string - % ( - value, - ", ".join(self.choices), - ), + f"invalid choice: {value}. (choose from {', '.join(self.choices)})", param, ctx, ) diff --git a/pymodbus/server/reactive/main.py b/pymodbus/server/reactive/main.py index dbbb3ab88..3f2b2261d 100644 --- a/pymodbus/server/reactive/main.py +++ b/pymodbus/server/reactive/main.py @@ -164,7 +164,7 @@ def getValues(self, fc_as_hex, address, count=1): :returns: The requested values from a:a+c """ if not self.zero_mode: - address = address + 1 + address += 1 Log.debug("getValues: fc-[{}] address-{}: count-{}", fc_as_hex, address, count) _block_type = self.decode(fc_as_hex) if self._randomize > 0 and _block_type in {"d", "i"}: @@ -215,7 +215,7 @@ def __init__(self, host, port, modbus_server): self._add_routes() self._counter = 0 self._modbus_server.response_manipulator = self.manipulate_response - self._manipulator_config = dict(**DEFAULT_MANIPULATOR) + self._manipulator_config = {**DEFAULT_MANIPULATOR} self._web_app.on_startup.append(self.start_modbus_server) self._web_app.on_shutdown.append(self.stop_modbus_server) diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index 34f8f32cf..6a0fc3565 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -151,7 +151,7 @@ def execute(self, request): # noqa: C901 if hasattr(request, "get_response_pdu_size"): response_pdu_size = request.get_response_pdu_size() if isinstance(self.client.framer, ModbusAsciiFramer): - response_pdu_size = response_pdu_size * 2 + response_pdu_size *= 2 if response_pdu_size: expected_response_length = ( self._calculate_response_length(response_pdu_size) diff --git a/requirements.txt b/requirements.txt index ca7440cd7..049ce6b3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -54,7 +54,7 @@ pre-commit==3.1.1 pyflakes==3.0.1 pydocstyle==6.3.0 pycodestyle==2.10.0 -pylint==2.15.10 +pylint==2.17.2 pytest==7.2.1 pytest-asyncio==0.20.3 pytest-cov==4.0.0 diff --git a/setup.cfg b/setup.cfg index 6f90fd699..4d5742b58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -194,7 +194,7 @@ deprecated-modules=regsub,TERMIOS,Bastion,rexec [pylint.exceptions] # Exceptions that will emit a warning when being caught. -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception [pylint.deprecated_builtins] diff --git a/test/test_client.py b/test/test_client.py index ce7c84592..293ae0ad6 100755 --- a/test/test_client.py +++ b/test/test_client.py @@ -289,7 +289,6 @@ async def test_client_modbusbaseclient(): ) as p_connect, mock.patch( "pymodbus.client.base.ModbusBaseClient.close" ) as p_close: - p_connect.return_value = True p_close.return_value = True with ModbusBaseClient(framer=ModbusAsciiFramer) as b_client: @@ -330,7 +329,6 @@ async def test_client_base_async(): ) as p_connect, mock.patch( "pymodbus.client.base.ModbusBaseClient.close" ) as p_close: - loop = asyncio.get_event_loop() p_connect.return_value = loop.create_future() p_connect.return_value.set_result(True)