diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 33c0f87d8..cdc98e691 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -21,7 +21,23 @@ _ProtocolFactory = Callable[[], BaseProtocol] _SSLContext = Union[bool, None, ssl.SSLContext] _TransProtPair = Tuple[BaseTransport, BaseProtocol] -class Server(AbstractServer): ... +class Server(AbstractServer): + if sys.version_info >= (3, 7): + def __init__( + self, + loop: AbstractEventLoop, + sockets: List[socket], + protocol_factory: _ProtocolFactory, + ssl_context: _SSLContext, + backlog: int, + ssl_handshake_timeout: Optional[float], + ) -> None: ... + else: + def __init__( + self, + loop: AbstractEventLoop, + sockets: List[socket], + ) -> None: ... class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): def run_forever(self) -> None: ... @@ -184,7 +200,7 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): ) -> _TransProtPair: ... if sys.version_info >= (3, 7): async def sock_sendfile( - self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, fallback: bool = ... + self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, fallback: Optional[bool] = ... ) -> int: ... @overload async def create_server( diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 8cda63a5c..521c69f32 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -242,7 +242,7 @@ class AbstractEventLoop(metaclass=ABCMeta): if sys.version_info >= (3, 7): @abstractmethod async def sock_sendfile( - self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, fallback: bool = ... + self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, fallback: Optional[bool] = ... ) -> int: ... @overload @abstractmethod diff --git a/stdlib/asyncio/proactor_events.pyi b/stdlib/asyncio/proactor_events.pyi index e3ebeb502..b4598cec8 100644 --- a/stdlib/asyncio/proactor_events.pyi +++ b/stdlib/asyncio/proactor_events.pyi @@ -1,9 +1,16 @@ +import sys from socket import socket -from typing import Any, Mapping, Optional -from typing_extensions import Literal +from typing import Any, Mapping, Optional, Type +from typing_extensions import Literal, Protocol from . import base_events, constants, events, futures, streams, transports +if sys.version_info >= (3, 8): + class _WarnCallbackProtocol(Protocol): + def __call__( + self, message: str, category: Optional[Type[Warning]] = ..., stacklevel: int = ..., source: Optional[Any] = ... + ) -> None: ... + class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport): def __init__( self, @@ -15,7 +22,10 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTr server: Optional[events.AbstractServer] = ..., ) -> None: ... def __repr__(self) -> str: ... - def __del__(self) -> None: ... + if sys.version_info >= (3, 8): + def __del__(self, _warn: _WarnCallbackProtocol = ...) -> None: ... + else: + def __del__(self) -> None: ... def get_write_buffer_size(self) -> int: ... class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTransport): diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 36aafedd7..a63672010 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -53,7 +53,8 @@ if sys.platform != "win32": **kwds: Any, ) -> events.AbstractServer: ... -class FlowControlMixin(protocols.Protocol): ... +class FlowControlMixin(protocols.Protocol): + def __init__(self, loop: Optional[events.AbstractEventLoop] = ...) -> None: ... class StreamReaderProtocol(FlowControlMixin, protocols.Protocol): def __init__( diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index 0c148fa1a..f8070017c 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -182,8 +182,8 @@ class Task(Future[_T], Generic[_T]): def get_coro(self) -> Any: ... def get_name(self) -> str: ... def set_name(self, __value: object) -> None: ... - def get_stack(self, *, limit: int = ...) -> List[FrameType]: ... - def print_stack(self, *, limit: int = ..., file: TextIO = ...) -> None: ... + def get_stack(self, *, limit: Optional[int] = ...) -> List[FrameType]: ... + def print_stack(self, *, limit: Optional[int] = ..., file: Optional[TextIO] = ...) -> None: ... if sys.version_info >= (3, 9): def cancel(self, msg: Optional[str] = ...) -> bool: ... else: diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index 7d3c1b208..855fca434 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -1,8 +1,9 @@ import sys import types +from socket import socket from typing import Any, Callable, Optional, Type, TypeVar -from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy +from .events import AbstractEventLoop, AbstractServer, BaseDefaultEventLoopPolicy, _ProtocolFactory, _SSLContext from .selector_events import BaseSelectorEventLoop _T1 = TypeVar("_T1", bound=AbstractChildWatcher) @@ -30,7 +31,17 @@ class SafeChildWatcher(BaseChildWatcher): class FastChildWatcher(BaseChildWatcher): def __enter__(self: _T3) -> _T3: ... -class _UnixSelectorEventLoop(BaseSelectorEventLoop): ... +class _UnixSelectorEventLoop(BaseSelectorEventLoop): + if sys.version_info < (3, 7): + async def create_unix_server( + self, + protocol_factory: _ProtocolFactory, + path: Optional[str] = ..., + *, + sock: Optional[socket] = ..., + backlog: int = ..., + ssl: _SSLContext = ..., + ) -> AbstractServer: ... class _UnixDefaultEventLoopPolicy(BaseDefaultEventLoopPolicy): def get_child_watcher(self) -> AbstractChildWatcher: ... diff --git a/tests/stubtest_whitelists/linux-py36.txt b/tests/stubtest_whitelists/linux-py36.txt index e7b8e1ede..f9c4b5f3b 100644 --- a/tests/stubtest_whitelists/linux-py36.txt +++ b/tests/stubtest_whitelists/linux-py36.txt @@ -1,4 +1,3 @@ -asyncio.unix_events._UnixSelectorEventLoop.create_unix_server ctypes.wintypes pwd.getpwnam ssl.PROTOCOL_SSLv3 diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index fc9c18b6d..d76c12b05 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -2,12 +2,12 @@ _collections_abc.AsyncGenerator.ag_await _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame _collections_abc.AsyncGenerator.ag_running -asyncio.Future.__init__ +asyncio.Future.__init__ # Usually initialized from c object asyncio.exceptions # Added in Python 3.8 asyncio.format_helpers # Added in Python 3.7 -asyncio.futures.Future.__init__ +asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures._TracebackLogger.__init__ -asyncio.runners +asyncio.runners # Added in Python 3.7 asyncio.staggered # Added in Python 3.8 asyncio.threads # Added in Python 3.9 asyncio.trsock # Added in Python 3.8 diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index fd15c7dc5..2d3dbb584 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -2,14 +2,12 @@ _collections_abc.AsyncGenerator.ag_await _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame _collections_abc.AsyncGenerator.ag_running -asyncio.AbstractEventLoop.sock_sendfile asyncio.compat # Removed in 3.7 -asyncio.Future.__init__ -asyncio.Future._callbacks -asyncio.events.AbstractEventLoop.sock_sendfile +asyncio.Future.__init__ # Usually initialized from c object +asyncio.Future._callbacks # Usually initialized from c object asyncio.exceptions # Added in Python 3.8 -asyncio.futures.Future.__init__ -asyncio.futures.Future._callbacks +asyncio.futures.Future.__init__ # Usually initialized from c object +asyncio.futures.Future._callbacks # Usually initialized from c object asyncio.staggered # Added in Python 3.8 asyncio.threads # Added in Python 3.9 asyncio.trsock # Added in Python 3.8 diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index d47b44350..4df61e9f3 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -14,14 +14,11 @@ ast.Ellipsis.__new__ ast.NameConstant.__new__ ast.Num.__new__ ast.Str.__new__ -asyncio.AbstractEventLoop.sock_sendfile asyncio.compat # removed in 3.7 -asyncio.Future.__init__ -asyncio.Future._callbacks -asyncio.events.AbstractEventLoop.sock_sendfile -asyncio.futures.Future.__init__ -asyncio.futures.Future._callbacks -asyncio.proactor_events._ProactorBasePipeTransport.__del__ +asyncio.Future.__init__ # Usually initialized from c object +asyncio.Future._callbacks # Usually initialized from c object +asyncio.futures.Future.__init__ # Usually initialized from c object +asyncio.futures.Future._callbacks # Usually initialized from c object asyncio.run # Bugfix involving this was backported to 3.8 asyncio.runners.run # It just hasn't been released yet asyncio.threads # Added in Python 3.9 diff --git a/tests/stubtest_whitelists/py39.txt b/tests/stubtest_whitelists/py39.txt index 3de34fa1e..d1855323b 100644 --- a/tests/stubtest_whitelists/py39.txt +++ b/tests/stubtest_whitelists/py39.txt @@ -24,13 +24,11 @@ ast.Index.__new__ ast.NameConstant.__new__ ast.Num.__new__ ast.Str.__new__ -asyncio.AbstractEventLoop.sock_sendfile asyncio.compat # module removed in 3.7 -asyncio.Future.__init__ -asyncio.Future._callbacks -asyncio.events.AbstractEventLoop.sock_sendfile -asyncio.futures.Future.__init__ -asyncio.futures.Future._callbacks +asyncio.Future.__init__ # Usually initialized from c object +asyncio.Future._callbacks # Usually initialized from c object +asyncio.futures.Future.__init__ # Usually initialized from c object +asyncio.futures.Future._callbacks # Usually initialized from c object asyncio.proactor_events._ProactorBasePipeTransport.__del__ builtins.dict.get collections.AsyncGenerator.ag_await diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 37fd1ea8d..42dabd8ef 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -35,22 +35,18 @@ abc.abstractclassmethod abc.abstractmethod abc.abstractstaticmethod argparse.Namespace.__getattr__ # The whole point of this class is its attributes are dynamic -asyncio.BaseEventLoop.subprocess_exec +asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them +# Condition functions are exported in __init__ asyncio.Condition.acquire asyncio.Condition.locked asyncio.Condition.release -asyncio.Task.get_stack -asyncio.Task.print_stack -asyncio.base_events.BaseEventLoop.subprocess_exec -asyncio.base_events.Server.__init__ +asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them +# Condition functions are exported in __init__ asyncio.locks.Condition.acquire asyncio.locks.Condition.locked asyncio.locks.Condition.release -asyncio.proactor_events.BaseProactorEventLoop.sock_recv -asyncio.selector_events.BaseSelectorEventLoop.sock_recv -asyncio.streams.FlowControlMixin.__init__ -asyncio.tasks.Task.get_stack -asyncio.tasks.Task.print_stack +asyncio.proactor_events.BaseProactorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation +asyncio.selector_events.BaseSelectorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation builtins.bytearray.__float__ builtins.bytearray.__int__ builtins.bytearray.append