Skip to content

Commit

Permalink
eliminate implicit optional for callback_disconnected (pymodbus-dev#1840
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alexrudd2 authored Oct 18, 2023
1 parent 786c7bc commit e0571ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions pymodbus/server/async_io.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e0571ca

Please sign in to comment.