From 147428dd526b7f41aba8b258661e74fb1675bac9 Mon Sep 17 00:00:00 2001 From: Walter Date: Tue, 20 May 2025 16:03:11 +0200 Subject: [PATCH] Add type annotations for protocol and protocol_factory --- serial_asyncio/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/serial_asyncio/__init__.py b/serial_asyncio/__init__.py index e173b56..e5f18f1 100644 --- a/serial_asyncio/__init__.py +++ b/serial_asyncio/__init__.py @@ -22,6 +22,9 @@ import serial from functools import partial +from typing import Callable, TypeVar +_T = TypeVar('T') + try: import termios except ImportError: @@ -46,7 +49,7 @@ class SerialTransport(asyncio.Transport): calling you back when it succeeds. """ - def __init__(self, loop, protocol, serial_instance): + def __init__(self, loop, protocol: asyncio.Protocol, serial_instance): super().__init__() self._loop = loop self._protocol = protocol @@ -423,7 +426,7 @@ async def _call_connection_lost(self, exc): self._loop = None -async def create_serial_connection(loop, protocol_factory, url, *args, **kwargs): +async def create_serial_connection(loop, protocol_factory: Callable[[], _T], url, *args, **kwargs) -> tuple[SerialTransport, _T]: """Create a connection to a new serial port instance. This function is a coroutine which will try to establish the @@ -468,7 +471,7 @@ async def create_serial_connection(loop, protocol_factory, url, *args, **kwargs) return transport, protocol -async def connection_for_serial(loop, protocol_factory, serial_instance): +async def connection_for_serial(loop, protocol_factory: Callable[[], _T], serial_instance) -> tuple[SerialTransport, _T]: """Create a connection to the given serial port instance. This function is a coroutine which will try to establish the