Skip to content

Commit

Permalink
pyserial: make serial.threaded.ReaderThread generic in the type of Pr…
Browse files Browse the repository at this point in the history
…otocol (#13425)
  • Loading branch information
x11x authored Jan 23, 2025
1 parent c546278 commit 3580566
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions stubs/pyserial/serial/threaded/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@ import threading
from _typeshed import ReadableBuffer
from collections.abc import Callable
from types import TracebackType
from typing import Generic, TypeVar
from typing_extensions import Self

from serial import Serial

_P = TypeVar("_P", bound=Protocol, default="Protocol") # noqa: Y020

class Protocol:
def connection_made(self, transport: ReaderThread) -> None: ...
def connection_made(self, transport: ReaderThread[Self]) -> None: ...
def data_received(self, data: bytes) -> None: ...
def connection_lost(self, exc: BaseException | None) -> None: ...

class Packetizer(Protocol):
TERMINATOR: bytes
buffer: bytearray
transport: ReaderThread | None
transport: ReaderThread[Self] | None
def handle_packet(self, packet: bytes) -> None: ...

class FramedPacket(Protocol):
START: bytes
STOP: bytes
packet: bytearray
in_packet: bool
transport: ReaderThread | None
transport: ReaderThread[Self] | None
def handle_packet(self, packet: bytes) -> None: ...
def handle_out_of_packet_data(self, data: bytes) -> None: ...

Expand All @@ -32,17 +35,17 @@ class LineReader(Packetizer):
def handle_line(self, line: str) -> None: ...
def write_line(self, text: str) -> None: ...

class ReaderThread(threading.Thread):
class ReaderThread(threading.Thread, Generic[_P]):
serial: Serial
protocol_factory: Callable[[], Protocol]
protocol_factory: Callable[[], _P]
alive: bool
protocol: Protocol
def __init__(self, serial_instance: Serial, protocol_factory: Callable[[], Protocol]) -> None: ...
protocol: _P
def __init__(self, serial_instance: Serial, protocol_factory: Callable[[], _P]) -> None: ...
def stop(self) -> None: ...
def write(self, data: ReadableBuffer) -> int: ...
def close(self) -> None: ...
def connect(self) -> tuple[Self, Protocol]: ...
def __enter__(self) -> Protocol: ...
def connect(self) -> tuple[Self, _P]: ...
def __enter__(self) -> _P: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None, /
) -> None: ...

0 comments on commit 3580566

Please sign in to comment.