Skip to content

Add type annotations for protocol and protocol_factory parameters #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions serial_asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import serial
from functools import partial

from typing import Callable, TypeVar
_T = TypeVar('T')

try:
import termios
except ImportError:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down