Skip to content

Commit 3aacb35

Browse files
authored
use a TypeVar for asyncio.BaseProtocol (#478)
* Revert "_TransProtPair is no longer defined in asyncio.events" This reverts commit fae5f7f. * fix mypy
1 parent c39afff commit 3aacb35

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

uvloop/loop.pyi

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _T = TypeVar('_T')
2121
_Context = Dict[str, Any]
2222
_ExceptionHandler = Callable[[asyncio.AbstractEventLoop, _Context], Any]
2323
_SSLContext = Union[bool, None, ssl.SSLContext]
24-
_TransProtPair = Tuple[asyncio.transports.BaseTransport, asyncio.protocols.BaseProtocol]
24+
_ProtocolT = TypeVar("_ProtocolT", bound=asyncio.BaseProtocol)
2525

2626
class Loop:
2727
def call_soon(
@@ -143,7 +143,7 @@ class Loop:
143143
@overload
144144
async def create_connection(
145145
self,
146-
protocol_factory: asyncio.events._ProtocolFactory,
146+
protocol_factory: Callable[[], _ProtocolT],
147147
host: str = ...,
148148
port: int = ...,
149149
*,
@@ -156,11 +156,11 @@ class Loop:
156156
server_hostname: Optional[str] = ...,
157157
ssl_handshake_timeout: Optional[float] = ...,
158158
ssl_shutdown_timeout: Optional[float] = ...,
159-
) -> _TransProtPair: ...
159+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
160160
@overload
161161
async def create_connection(
162162
self,
163-
protocol_factory: asyncio.events._ProtocolFactory,
163+
protocol_factory: Callable[[], _ProtocolT],
164164
host: None = ...,
165165
port: None = ...,
166166
*,
@@ -173,7 +173,7 @@ class Loop:
173173
server_hostname: Optional[str] = ...,
174174
ssl_handshake_timeout: Optional[float] = ...,
175175
ssl_shutdown_timeout: Optional[float] = ...,
176-
) -> _TransProtPair: ...
176+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
177177
async def create_unix_server(
178178
self,
179179
protocol_factory: asyncio.events._ProtocolFactory,
@@ -188,15 +188,15 @@ class Loop:
188188
) -> asyncio.AbstractServer: ...
189189
async def create_unix_connection(
190190
self,
191-
protocol_factory: asyncio.events._ProtocolFactory,
191+
protocol_factory: Callable[[], _ProtocolT],
192192
path: Optional[str] = ...,
193193
*,
194194
ssl: _SSLContext = ...,
195195
sock: Optional[socket] = ...,
196196
server_hostname: Optional[str] = ...,
197197
ssl_handshake_timeout: Optional[float] = ...,
198198
ssl_shutdown_timeout: Optional[float] = ...,
199-
) -> _TransProtPair: ...
199+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
200200
def default_exception_handler(self, context: _Context) -> None: ...
201201
def get_exception_handler(self) -> Optional[_ExceptionHandler]: ...
202202
def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ...
@@ -212,49 +212,49 @@ class Loop:
212212
async def sock_connect(self, sock: socket, address: _Address) -> None: ...
213213
async def connect_accepted_socket(
214214
self,
215-
protocol_factory: asyncio.events._ProtocolFactory,
215+
protocol_factory: Callable[[], _ProtocolT],
216216
sock: socket,
217217
*,
218218
ssl: _SSLContext = ...,
219219
ssl_handshake_timeout: Optional[float] = ...,
220220
ssl_shutdown_timeout: Optional[float] = ...,
221-
) -> _TransProtPair: ...
221+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
222222
async def run_in_executor(
223223
self, executor: Any, func: Callable[..., _T], *args: Any
224224
) -> _T: ...
225225
def set_default_executor(self, executor: Any) -> None: ...
226226
async def subprocess_shell(
227227
self,
228-
protocol_factory: asyncio.events._ProtocolFactory,
228+
protocol_factory: Callable[[], _ProtocolT],
229229
cmd: Union[bytes, str],
230230
*,
231231
stdin: Any = ...,
232232
stdout: Any = ...,
233233
stderr: Any = ...,
234234
**kwargs: Any,
235-
) -> _TransProtPair: ...
235+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
236236
async def subprocess_exec(
237237
self,
238-
protocol_factory: asyncio.events._ProtocolFactory,
238+
protocol_factory: Callable[[], _ProtocolT],
239239
*args: Any,
240240
stdin: Any = ...,
241241
stdout: Any = ...,
242242
stderr: Any = ...,
243243
**kwargs: Any,
244-
) -> _TransProtPair: ...
244+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
245245
async def connect_read_pipe(
246-
self, protocol_factory: asyncio.events._ProtocolFactory, pipe: Any
247-
) -> _TransProtPair: ...
246+
self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
247+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
248248
async def connect_write_pipe(
249-
self, protocol_factory: asyncio.events._ProtocolFactory, pipe: Any
250-
) -> _TransProtPair: ...
249+
self, protocol_factory: Callable[[], _ProtocolT], pipe: Any
250+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
251251
def add_signal_handler(
252252
self, sig: int, callback: Callable[..., Any], *args: Any
253253
) -> None: ...
254254
def remove_signal_handler(self, sig: int) -> bool: ...
255255
async def create_datagram_endpoint(
256256
self,
257-
protocol_factory: asyncio.events._ProtocolFactory,
257+
protocol_factory: Callable[[], _ProtocolT],
258258
local_addr: Optional[Tuple[str, int]] = ...,
259259
remote_addr: Optional[Tuple[str, int]] = ...,
260260
*,
@@ -265,7 +265,7 @@ class Loop:
265265
reuse_port: Optional[bool] = ...,
266266
allow_broadcast: Optional[bool] = ...,
267267
sock: Optional[socket] = ...,
268-
) -> _TransProtPair: ...
268+
) -> tuple[asyncio.BaseProtocol, _ProtocolT]: ...
269269
async def shutdown_asyncgens(self) -> None: ...
270270
async def shutdown_default_executor(self) -> None: ...
271271
# Loop doesn't implement these, but since they are marked as abstract in typeshed,

0 commit comments

Comments
 (0)