From e669cdf1cb71dfc617c9a4b9796a84246eb76d40 Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Tue, 17 Oct 2023 15:39:38 -0500 Subject: [PATCH] pre-commit run --all-files --- pymodbus/device.py | 48 ++++++------------- pymodbus/utilities.py | 22 ++++----- .../test_register_read_messages.py | 3 +- test/sub_server/test_server_asyncio.py | 8 ++-- test/test_transaction.py | 6 +-- 5 files changed, 30 insertions(+), 57 deletions(-) diff --git a/pymodbus/device.py b/pymodbus/device.py index ff262b03d..0060f5540 100644 --- a/pymodbus/device.py +++ b/pymodbus/device.py @@ -220,23 +220,15 @@ def __str__(self): # -------------------------------------------------------------------------# # Properties # -------------------------------------------------------------------------# - VendorName = dict_property( - lambda s: s.__data, 0 # pylint: disable=protected-access - ) - ProductCode = dict_property( - lambda s: s.__data, 1 # pylint: disable=protected-access - ) - MajorMinorRevision = dict_property( - lambda s: s.__data, 2 # pylint: disable=protected-access - ) + # fmt: off + VendorName = dict_property(lambda s: s.__data, 0) # pylint: disable=protected-access + ProductCode = dict_property(lambda s: s.__data, 1) # pylint: disable=protected-access + MajorMinorRevision = dict_property(lambda s: s.__data, 2) # pylint: disable=protected-access VendorUrl = dict_property(lambda s: s.__data, 3) # pylint: disable=protected-access - ProductName = dict_property( - lambda s: s.__data, 4 # pylint: disable=protected-access - ) + ProductName = dict_property(lambda s: s.__data, 4) # pylint: disable=protected-access ModelName = dict_property(lambda s: s.__data, 5) # pylint: disable=protected-access - UserApplicationName = dict_property( - lambda s: s.__data, 6 # pylint: disable=protected-access - ) + UserApplicationName = dict_property(lambda s: s.__data, 6) # pylint: disable=protected-access + # fmt: on class DeviceInformationFactory: # pylint: disable=too-few-public-methods @@ -428,27 +420,17 @@ def summary(self): # -------------------------------------------------------------------------# # Properties # -------------------------------------------------------------------------# - BusMessage = dict_property( - lambda s: s.__data, 0 # pylint: disable=protected-access - ) - BusCommunicationError = dict_property( - lambda s: s.__data, 1 # pylint: disable=protected-access - ) - BusExceptionError = dict_property( - lambda s: s.__data, 2 # pylint: disable=protected-access - ) - SlaveMessage = dict_property( - lambda s: s.__data, 3 # pylint: disable=protected-access - ) - SlaveNoResponse = dict_property( - lambda s: s.__data, 4 # pylint: disable=protected-access - ) + # fmt: off + BusMessage = dict_property(lambda s: s.__data, 0) # pylint: disable=protected-access + BusCommunicationError = dict_property(lambda s: s.__data, 1) # pylint: disable=protected-access + BusExceptionError = dict_property(lambda s: s.__data, 2) # pylint: disable=protected-access + SlaveMessage = dict_property(lambda s: s.__data, 3) # pylint: disable=protected-access + SlaveNoResponse = dict_property(lambda s: s.__data, 4) # pylint: disable=protected-access SlaveNAK = dict_property(lambda s: s.__data, 5) # pylint: disable=protected-access SlaveBusy = dict_property(lambda s: s.__data, 6) # pylint: disable=protected-access - BusCharacterOverrun = dict_property( - lambda s: s.__data, 7 # pylint: disable=protected-access - ) + BusCharacterOverrun = dict_property(lambda s: s.__data, 7) # pylint: disable=protected-access Event = dict_property(lambda s: s.__data, 8) # pylint: disable=protected-access + # fmt: on # ---------------------------------------------------------------------------# diff --git a/pymodbus/utilities.py b/pymodbus/utilities.py index 37cc7069c..bedc81006 100644 --- a/pymodbus/utilities.py +++ b/pymodbus/utilities.py @@ -77,26 +77,20 @@ def dict_property(store, index): getter = lambda self: store( # pylint: disable=unnecessary-lambda-assignment self )[index] - setter = ( - lambda self, value: store( # pylint: disable=unnecessary-lambda-assignment - self - ).__setitem__(index, value) - ) + setter = lambda self, value: store( # pylint: disable=unnecessary-lambda-assignment + self + ).__setitem__(index, value) elif isinstance(store, str): getter = lambda self: self.__getattribute__( # pylint: disable=unnecessary-dunder-call,unnecessary-lambda-assignment store - )[ - index - ] + )[index] setter = lambda self, value: self.__getattribute__( # pylint: disable=unnecessary-dunder-call,unnecessary-lambda-assignment store - ).__setitem__( - index, value - ) + ).__setitem__(index, value) else: - getter = lambda self: store[ # pylint: disable=unnecessary-lambda-assignment - index - ] + getter = ( + lambda self: store[index] # pylint: disable=unnecessary-lambda-assignment + ) setter = lambda self, value: store.__setitem__( # pylint: disable=unnecessary-lambda-assignment index, value ) diff --git a/test/sub_messages/test_register_read_messages.py b/test/sub_messages/test_register_read_messages.py index b9e19967a..dcb1ef6c5 100644 --- a/test/sub_messages/test_register_read_messages.py +++ b/test/sub_messages/test_register_read_messages.py @@ -58,8 +58,7 @@ def setup_method(self): ReadWriteMultipleRegistersRequest( write_registers=0xAB, **arguments, - ): b"\x00\x01\x00\x05\x00\x01\x00" - b"\x01\x02\x00\xAB", + ): b"\x00\x01\x00\x05\x00\x01\x00" b"\x01\x02\x00\xAB", } self.response_read = { ReadRegistersResponseBase(self.values): TEST_MESSAGE, diff --git a/test/sub_server/test_server_asyncio.py b/test/sub_server/test_server_asyncio.py index e0ba7ccbc..42a5d2848 100755 --- a/test/sub_server/test_server_asyncio.py +++ b/test/sub_server/test_server_asyncio.py @@ -323,13 +323,13 @@ async def test_async_udp_server_serve_forever_twice(self): async def test_async_udp_server_roundtrip(self): """Test sending and receiving data on udp socket""" - expected_response = b"\x01\x00\x00\x00\x00\x05\x01\x03\x02\x00\x11" # value of 17 as per context + expected_response = ( + b"\x01\x00\x00\x00\x00\x05\x01\x03\x02\x00\x11" + ) # value of 17 as per context BasicClient.dataTo = TEST_DATA # slave 1, read register BasicClient.done = asyncio.Future() await self.start_server(do_udp=True) - random_port = self.server.transport._sock.getsockname()[ # pylint: disable=protected-access - 1 - ] + random_port = self.server.transport._sock.getsockname()[1] # pylint: disable=protected-access transport, _ = await self.loop.create_datagram_endpoint( BasicClient, remote_addr=("127.0.0.1", random_port) ) diff --git a/test/test_transaction.py b/test/test_transaction.py index fb236f2d5..0a05d1c1b 100755 --- a/test/test_transaction.py +++ b/test/test_transaction.py @@ -65,10 +65,8 @@ def test_calculate_expected_response_length(self): self._tm.client = mock.MagicMock() self._tm.client.framer = mock.MagicMock() self._tm._set_adu_size() # pylint: disable=protected-access - assert ( - not self._tm._calculate_response_length( # pylint: disable=protected-access - 0 - ) + assert not self._tm._calculate_response_length( # pylint: disable=protected-access + 0 ) self._tm.base_adu_size = 10 assert (