From 9bb1f5023034ad464147858dc241660ef1f58af2 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Wed, 19 Apr 2023 20:34:07 +0200 Subject: [PATCH] pylint pleaser. --- pymodbus/client/base.py | 2 +- pymodbus/transport/base.py | 45 ++++++++++++++------------------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index a8550c2181..c83de58589 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -96,7 +96,7 @@ def __init__( # pylint: disable=too-many-arguments **kwargs: Any, ) -> None: """Initialize a client instance.""" - BaseTransport.__init__(self, framer, 0, "Client") + BaseTransport.__init__(self) self.params = self._params() self.params.framer = framer self.params.timeout = float(timeout) diff --git a/pymodbus/transport/base.py b/pymodbus/transport/base.py index 8fe63337ab..a28fa3d246 100644 --- a/pymodbus/transport/base.py +++ b/pymodbus/transport/base.py @@ -30,33 +30,20 @@ class BaseTransport: This class is not available in the pymodbus API, and should not be referenced in Applications. """ - def __init__( # pylint: disable=too-many-arguments - self, - framer: ModbusFramer, - slaves: list[int], - comm_name: str = "NO NAME", - reconnect_delay: int = 0, - reconnect_delay_max: int = 0, - retries_send: int = 0, - retry_on_empty: bool = False, - timeout_connect: int = 10, - timeout_comm: int = 5, - on_connection_made: Callable[[str], None] | None = None, - on_connection_lost: Callable[[str, Exception], None] | None = None, - ) -> None: + def __init__(self) -> None: """Initialize a transport instance.""" - # parameter variables - self.framer = framer - self.slaves = slaves - self.comm_name = comm_name - self.reconnect_delay = reconnect_delay - self.reconnect_delay_max = reconnect_delay_max - self.retries_send = retries_send - self.retry_on_empty = retry_on_empty - self.timeout_connect = timeout_connect - self.timeout_comm = timeout_comm - self.on_connection_made = on_connection_made - self.on_connection_lost = on_connection_lost + # parameter variables, overwritten in child classes + self.framer: ModbusFramer | None = None + self.slaves: list[int] = [] + self.comm_name: str = "" + self.reconnect_delay: int = -1 + self.reconnect_delay_max: int = -1 + self.retries_send: int = -1 + self.retry_on_empty: int = -1 + self.timeout_connect: bool = None + self.timeout_comm: int = -1 + self.on_connection_made: Callable[[str], None] = None + self.on_connection_lost: Callable[[str, Exception], None] | None = None # local variables self.reconnect_delay_current: int = 0 @@ -73,7 +60,7 @@ def connection_made(self, transport: Any): self.transport = transport Log.debug("Connected {}", self.comm_name) if self.on_connection_made: - self.on_connection_made(self.comm_name) + self.on_connection_made(self.comm_name) # pylint: disable=not-callable def connection_lost(self, reason: Exception): """Call from asyncio, when the connection is lost or closed. @@ -83,7 +70,9 @@ def connection_lost(self, reason: Exception): self.transport = None Log.debug("Connection lost {} due to {}", self.comm_name, reason) if self.on_connection_lost: - self.on_connection_lost(self.comm_name, reason) + self.on_connection_lost( # pylint: disable=not-callable + self.comm_name, reason + ) def data_received(self, data: bytes): """Call when some data is received.