@@ -2,27 +2,30 @@ import threading
2
2
from _typeshed import ReadableBuffer
3
3
from collections .abc import Callable
4
4
from types import TracebackType
5
+ from typing import Generic , TypeVar
5
6
from typing_extensions import Self
6
7
7
8
from serial import Serial
8
9
10
+ _P = TypeVar ("_P" , bound = Protocol , default = "Protocol" ) # noqa: Y020
11
+
9
12
class Protocol :
10
- def connection_made (self , transport : ReaderThread ) -> None : ...
13
+ def connection_made (self , transport : ReaderThread [ Self ] ) -> None : ...
11
14
def data_received (self , data : bytes ) -> None : ...
12
15
def connection_lost (self , exc : BaseException | None ) -> None : ...
13
16
14
17
class Packetizer (Protocol ):
15
18
TERMINATOR : bytes
16
19
buffer : bytearray
17
- transport : ReaderThread | None
20
+ transport : ReaderThread [ Self ] | None
18
21
def handle_packet (self , packet : bytes ) -> None : ...
19
22
20
23
class FramedPacket (Protocol ):
21
24
START : bytes
22
25
STOP : bytes
23
26
packet : bytearray
24
27
in_packet : bool
25
- transport : ReaderThread | None
28
+ transport : ReaderThread [ Self ] | None
26
29
def handle_packet (self , packet : bytes ) -> None : ...
27
30
def handle_out_of_packet_data (self , data : bytes ) -> None : ...
28
31
@@ -32,17 +35,17 @@ class LineReader(Packetizer):
32
35
def handle_line (self , line : str ) -> None : ...
33
36
def write_line (self , text : str ) -> None : ...
34
37
35
- class ReaderThread (threading .Thread ):
38
+ class ReaderThread (threading .Thread , Generic [ _P ] ):
36
39
serial : Serial
37
- protocol_factory : Callable [[], Protocol ]
40
+ protocol_factory : Callable [[], _P ]
38
41
alive : bool
39
- protocol : Protocol
40
- def __init__ (self , serial_instance : Serial , protocol_factory : Callable [[], Protocol ]) -> None : ...
42
+ protocol : _P
43
+ def __init__ (self , serial_instance : Serial , protocol_factory : Callable [[], _P ]) -> None : ...
41
44
def stop (self ) -> None : ...
42
45
def write (self , data : ReadableBuffer ) -> int : ...
43
46
def close (self ) -> None : ...
44
- def connect (self ) -> tuple [Self , Protocol ]: ...
45
- def __enter__ (self ) -> Protocol : ...
47
+ def connect (self ) -> tuple [Self , _P ]: ...
48
+ def __enter__ (self ) -> _P : ...
46
49
def __exit__ (
47
50
self , exc_type : type [BaseException ] | None , exc_val : BaseException | None , exc_tb : TracebackType | None , /
48
51
) -> None : ...
0 commit comments