Skip to content

Commit 6d80efd

Browse files
alexrudd2MAKOMO
andauthored
Eliminate implicit optional in transport_serial (#1843)
Co-authored-by: MAKOMO <[email protected]>
1 parent 01ad131 commit 6d80efd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pymodbus/transport/transport_serial.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""asyncio serial support for modbus (based on pyserial)."""
2+
from __future__ import annotations
3+
24
import asyncio
35
import contextlib
46
import os
5-
from typing import Tuple
67

78

89
with contextlib.suppress(ImportError):
@@ -14,13 +15,13 @@ class SerialTransport(asyncio.Transport):
1415

1516
force_poll: bool = False
1617

17-
def __init__(self, loop, protocol, *args, **kwargs):
18+
def __init__(self, loop, protocol, *args, **kwargs) -> None:
1819
"""Initialize."""
1920
super().__init__()
2021
self.async_loop = loop
2122
self._protocol: asyncio.BaseProtocol = protocol
2223
self.sync_serial = serial.serial_for_url(*args, **kwargs)
23-
self._write_buffer = []
24+
self._write_buffer: list[bytes] = []
2425
self.poll_task = None
2526
self._poll_wait_time = 0.0005
2627
self.sync_serial.timeout = 0
@@ -53,13 +54,13 @@ def close(self, exc=None):
5354
with contextlib.suppress(Exception):
5455
self._protocol.connection_lost(exc)
5556

56-
def write(self, data):
57+
def write(self, data) -> None:
5758
"""Write some data to the transport."""
5859
self._write_buffer.append(data)
5960
if not self.poll_task:
6061
self.async_loop.add_writer(self.sync_serial.fileno(), self._write_ready)
6162

62-
def flush(self):
63+
def flush(self) -> None:
6364
"""Clear output buffer and stops any more data being written"""
6465
if not self.poll_task:
6566
self.async_loop.remove_writer(self.sync_serial.fileno())
@@ -81,7 +82,7 @@ def set_protocol(self, protocol: asyncio.BaseProtocol) -> None:
8182
"""Set protocol"""
8283
self._protocol = protocol
8384

84-
def get_write_buffer_limits(self) -> Tuple[int, int]:
85+
def get_write_buffer_limits(self) -> tuple[int, int]:
8586
"""Return buffer sizes"""
8687
return (1, 1024)
8788

@@ -159,7 +160,9 @@ async def _polling_task(self):
159160
pass
160161

161162

162-
async def create_serial_connection(loop, protocol_factory, *args, **kwargs):
163+
async def create_serial_connection(
164+
loop, protocol_factory, *args, **kwargs
165+
) -> tuple[asyncio.Transport, asyncio.BaseProtocol]:
163166
"""Create a connection to a new serial port instance."""
164167
protocol = protocol_factory()
165168
transport = SerialTransport(loop, protocol, *args, **kwargs)

0 commit comments

Comments
 (0)