diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index a3b85ae59..44e575483 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -219,7 +219,7 @@ def callback_data(self, data: bytes, addr: tuple = None) -> int: self.framer.processIncomingPacket(data, self._handle_response, slave=0) return len(data) - def callback_disconnected(self, _reason: Exception) -> None: + def callback_disconnected(self, _reason: Exception | None) -> None: """Handle lost connection""" for tid in list(self.transaction): self.raise_future( diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index 22f241abd..4eb6654ea 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -1,11 +1,12 @@ """Implementation of a Threaded Modbus Server.""" # pylint: disable=missing-type-doc +from __future__ import annotations + import asyncio import os import time import traceback from contextlib import suppress -from typing import Union from pymodbus.datastore import ModbusServerContext from pymodbus.device import ModbusControlBlock, ModbusDeviceIdentification @@ -74,7 +75,7 @@ def callback_connected(self) -> None: traceback.format_exc(), ) - def callback_disconnected(self, call_exc: Exception) -> None: + def callback_disconnected(self, call_exc: Exception | None) -> None: """Call when connection is lost.""" try: if self.handler_task: @@ -229,9 +230,9 @@ async def _recv_(self): # pragma: no cover result = None return result - def callback_data(self, data: bytes, addr: tuple = None) -> int: + def callback_data(self, data: bytes, addr: tuple = ()) -> int: """Handle received data.""" - if addr: + if addr != (): self.receive_queue.put_nowait((data, addr)) else: self.receive_queue.put_nowait(data) @@ -554,7 +555,7 @@ class _serverList: :meta private: """ - active_server: Union[ModbusTcpServer, ModbusUdpServer, ModbusSerialServer] = None + active_server: ModbusTcpServer | ModbusUdpServer | ModbusSerialServer def __init__(self, server): """Register new server.""" diff --git a/pymodbus/transport/transport.py b/pymodbus/transport/transport.py index a1bbfd661..245b656cf 100644 --- a/pymodbus/transport/transport.py +++ b/pymodbus/transport/transport.py @@ -374,7 +374,7 @@ def callback_connected(self) -> None: """Call when connection is succcesfull.""" Log.debug("callback_connected called") - def callback_disconnected(self, exc: Exception) -> None: + def callback_disconnected(self, exc: Exception | None) -> None: """Call when connection is lost.""" Log.debug("callback_disconnected called: {}", exc)