From ec572510106125376f592298276527aafa045ed8 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 20 Apr 2020 17:56:24 -0700 Subject: [PATCH] asyncio.events: various fixes (#3931) - connect_accepted_socket isn't a member of AbstractEventLoop, only BaseEventLoop - fix types of arguments with defaults. some of these functions could have their signatures improved with overloads to reduce false negatives - correctly mark a positional-only argument - remove abstractmethod from methods that don't have abstractmethod and go unimplemented in practice --- stdlib/3/asyncio/events.pyi | 19 ++++----------- stdlib/3/asyncio/proactor_events.pyi | 31 ------------------------ stdlib/3/asyncio/selector_events.pyi | 31 +----------------------- tests/stubtest_whitelists/py35.txt | 1 + tests/stubtest_whitelists/py36.txt | 1 + tests/stubtest_whitelists/py37.txt | 4 --- tests/stubtest_whitelists/py38.txt | 6 ----- tests/stubtest_whitelists/py3_common.txt | 8 ------ 8 files changed, 8 insertions(+), 93 deletions(-) diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index f90c98cbe..a5815c8bd 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -192,18 +192,13 @@ class AbstractEventLoop(metaclass=ABCMeta): family: int = ..., flags: int = ..., sock: socket = ..., backlog: int = ..., ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ... - @abstractmethod - async def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ..., - sock: Optional[socket] = ..., server_hostname: str = ..., + async def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: Optional[str] = ..., *, ssl: _SSLContext = ..., + sock: Optional[socket] = ..., server_hostname: Optional[str] = ..., ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... - @abstractmethod - async def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ..., + async def create_unix_server(self, protocol_factory: _ProtocolFactory, path: Optional[str] = ..., *, sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ..., ssl_handshake_timeout: Optional[float] = ..., start_serving: bool = ...) -> AbstractServer: ... @abstractmethod - async def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ..., - ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... - @abstractmethod async def sendfile(self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, fallback: bool = ...) -> int: ... @abstractmethod @@ -225,15 +220,11 @@ class AbstractEventLoop(metaclass=ABCMeta): sock: socket, backlog: int = ..., ssl: _SSLContext = ..., reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ...) -> AbstractServer: ... - @abstractmethod async def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, ssl: _SSLContext = ..., sock: Optional[socket] = ..., - server_hostname: str = ...) -> _TransProtPair: ... - @abstractmethod + server_hostname: Optional[str] = ...) -> _TransProtPair: ... async def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> AbstractServer: ... - @abstractmethod - async def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...) -> _TransProtPair: ... @abstractmethod async def create_datagram_endpoint(self, protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]] = ..., remote_addr: Optional[Tuple[str, int]] = ..., *, @@ -332,7 +323,7 @@ def new_event_loop() -> AbstractEventLoop: ... def get_child_watcher() -> AbstractChildWatcher: ... def set_child_watcher(watcher: AbstractChildWatcher) -> None: ... -def _set_running_loop(loop: Optional[AbstractEventLoop]) -> None: ... +def _set_running_loop(__loop: Optional[AbstractEventLoop]) -> None: ... def _get_running_loop() -> AbstractEventLoop: ... if sys.version_info >= (3, 7): diff --git a/stdlib/3/asyncio/proactor_events.pyi b/stdlib/3/asyncio/proactor_events.pyi index f7bc90db1..0ad5451fd 100644 --- a/stdlib/3/asyncio/proactor_events.pyi +++ b/stdlib/3/asyncio/proactor_events.pyi @@ -46,35 +46,4 @@ class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePip def write_eof(self) -> None: ... class BaseProactorEventLoop(base_events.BaseEventLoop): - def __init__(self, proactor: Any) -> None: ... - # The methods below don't actually exist directly, ProactorEventLoops do not implement them. However, they are - # needed to satisfy mypy - if sys.version_info >= (3, 7): - async def create_unix_connection( - self, - protocol_factory: events._ProtocolFactory, - path: _Path, - *, - ssl: events._SSLContext = ..., - sock: Optional[socket] = ..., - server_hostname: str = ..., - ssl_handshake_timeout: Optional[float] = ..., - ) -> events._TransProtPair: ... - async def create_unix_server( - self, - protocol_factory: events._ProtocolFactory, - path: _Path, - *, - sock: Optional[socket] = ..., - backlog: int = ..., - ssl: events._SSLContext = ..., - ssl_handshake_timeout: Optional[float] = ..., - start_serving: bool = ..., - ) -> events.AbstractServer: ... - else: - async def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *, - ssl: events._SSLContext = ..., sock: Optional[socket] = ..., - server_hostname: str = ...) -> events._TransProtPair: ... - async def create_unix_server(self, protocol_factory: events._ProtocolFactory, path: str, *, - sock: Optional[socket] = ..., backlog: int = ..., ssl: events._SSLContext = ...) -> events.AbstractServer: ... diff --git a/stdlib/3/asyncio/selector_events.pyi b/stdlib/3/asyncio/selector_events.pyi index 5d63cdf8f..1af86855b 100644 --- a/stdlib/3/asyncio/selector_events.pyi +++ b/stdlib/3/asyncio/selector_events.pyi @@ -1,7 +1,7 @@ import selectors import sys from socket import socket -from typing import Optional, Union +from typing import Any, Optional, Union from . import base_events, events @@ -12,33 +12,4 @@ else: _Path = str class BaseSelectorEventLoop(base_events.BaseEventLoop): - def __init__(self, selector: Optional[selectors.BaseSelector] = ...) -> None: ... - if sys.version_info >= (3, 7): - async def create_unix_connection( - self, - protocol_factory: events._ProtocolFactory, - path: _Path, - *, - ssl: events._SSLContext = ..., - sock: Optional[socket] = ..., - server_hostname: str = ..., - ssl_handshake_timeout: Optional[float] = ..., - ) -> events._TransProtPair: ... - async def create_unix_server( - self, - protocol_factory: events._ProtocolFactory, - path: _Path, - *, - sock: Optional[socket] = ..., - backlog: int = ..., - ssl: events._SSLContext = ..., - ssl_handshake_timeout: Optional[float] = ..., - start_serving: bool = ..., - ) -> events.AbstractServer: ... - else: - async def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *, - ssl: events._SSLContext = ..., sock: Optional[socket] = ..., - server_hostname: str = ...) -> events._TransProtPair: ... - async def create_unix_server(self, protocol_factory: events._ProtocolFactory, path: str, *, - sock: Optional[socket] = ..., backlog: int = ..., ssl: events._SSLContext = ...) -> events.AbstractServer: ... diff --git a/tests/stubtest_whitelists/py35.txt b/tests/stubtest_whitelists/py35.txt index 069fd79cc..77f9404fc 100644 --- a/tests/stubtest_whitelists/py35.txt +++ b/tests/stubtest_whitelists/py35.txt @@ -15,6 +15,7 @@ asyncio.futures._TracebackLogger.__init__ asyncio.protocols.BufferedProtocol asyncio.runners asyncio.tasks.Task.__init__ +asyncio.unix_events._UnixSelectorEventLoop.create_unix_server bdb.GENERATOR_AND_COROUTINE_FLAGS builtins.str.maketrans cmath.log diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index 410d9f5ee..6cbcabace 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -8,6 +8,7 @@ asyncio.futures._TracebackLogger.__init__ asyncio.protocols.BufferedProtocol asyncio.runners asyncio.tasks.Task._wakeup +asyncio.unix_events._UnixSelectorEventLoop.create_unix_server builtins.str.maketrans cmath.log codecs.StreamRecoder.seek diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index e90bf3013..8c7c6aeeb 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -2,14 +2,12 @@ _bisect.bisect _bisect.insort _tracemalloc._get_object_traceback _tracemalloc.start -asyncio.AbstractEventLoop.create_unix_server asyncio.AbstractEventLoop.sock_sendfile asyncio.Future.__init__ asyncio.Future._callbacks asyncio.Future._schedule_callbacks asyncio.Handle.__init__ asyncio.TimerHandle.__init__ -asyncio.events.AbstractEventLoop.create_unix_server asyncio.events.AbstractEventLoop.sock_sendfile asyncio.events.Handle.__init__ asyncio.events.TimerHandle.__init__ @@ -17,8 +15,6 @@ asyncio.exceptions asyncio.futures.Future.__init__ asyncio.futures.Future._callbacks asyncio.futures.Future._schedule_callbacks -asyncio.proactor_events.BaseProactorEventLoop.create_unix_server -asyncio.selector_events.BaseSelectorEventLoop.create_unix_server builtins.dict.get builtins.reversed builtins.str.maketrans diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index c8ce2a5b2..ae9e8702c 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -5,7 +5,6 @@ _thread._ExceptHookArgs _tracemalloc._get_object_traceback _tracemalloc.start _weakref.getweakrefcount -asyncio.AbstractEventLoop.create_unix_server asyncio.AbstractEventLoop.sock_sendfile asyncio.Future.__init__ asyncio.Future._callbacks @@ -19,21 +18,16 @@ asyncio.Task.set_exception asyncio.Task.set_name asyncio.Task.set_result asyncio.TimerHandle.__init__ -asyncio._set_running_loop -asyncio.events.AbstractEventLoop.create_unix_server asyncio.events.AbstractEventLoop.sock_sendfile asyncio.events.Handle.__init__ asyncio.events.TimerHandle.__init__ -asyncio.events._set_running_loop asyncio.futures.Future.__init__ asyncio.futures.Future._callbacks asyncio.futures.Future._schedule_callbacks asyncio.futures.Future.remove_done_callback asyncio.futures.Future.set_exception asyncio.futures.Future.set_result -asyncio.proactor_events.BaseProactorEventLoop.create_unix_server asyncio.proactor_events._ProactorBasePipeTransport.__del__ -asyncio.selector_events.BaseSelectorEventLoop.create_unix_server asyncio.tasks.Task.remove_done_callback asyncio.tasks.Task.set_exception asyncio.tasks.Task.set_name diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 1d79408e8..0b367f6d8 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -15,8 +15,6 @@ abc.abstractstaticmethod aifc.open aifc.openfp argparse.Namespace.__getattr__ -asyncio.AbstractEventLoop.connect_accepted_socket -asyncio.AbstractEventLoop.create_unix_connection asyncio.BaseChildWatcher asyncio.BaseEventLoop.subprocess_exec asyncio.Condition.acquire @@ -32,8 +30,6 @@ asyncio.Task.get_stack asyncio.Task.print_stack asyncio.WriteTransport.set_write_buffer_limits asyncio.base_events.BaseEventLoop.subprocess_exec -asyncio.events.AbstractEventLoop.connect_accepted_socket -asyncio.events.AbstractEventLoop.create_unix_connection asyncio.futures.Future._copy_state asyncio.futures.wrap_future asyncio.locks.Condition.acquire @@ -41,11 +37,9 @@ asyncio.locks.Condition.locked asyncio.locks.Condition.release asyncio.open_connection asyncio.open_unix_connection -asyncio.proactor_events.BaseProactorEventLoop.create_unix_connection asyncio.proactor_events.BaseProactorEventLoop.sock_recv asyncio.queues.Queue._consume_done_getters asyncio.queues.Queue._consume_done_putters -asyncio.selector_events.BaseSelectorEventLoop.create_unix_connection asyncio.selector_events.BaseSelectorEventLoop.sock_recv asyncio.sleep asyncio.start_unix_server @@ -59,8 +53,6 @@ asyncio.tasks.Task.print_stack asyncio.tasks.sleep asyncio.transports.WriteTransport.set_write_buffer_limits asyncio.transports._FlowControlMixin.set_write_buffer_limits -asyncio.unix_events._UnixSelectorEventLoop.create_unix_connection -asyncio.unix_events._UnixSelectorEventLoop.create_unix_server asyncio.windows_events asyncio.windows_utils asyncio.wrap_future