diff --git a/stdlib/@tests/test_cases/asyncio/check_create_server.py b/stdlib/@tests/test_cases/asyncio/check_create_server.py new file mode 100644 index 000000000000..1275ffe4823a --- /dev/null +++ b/stdlib/@tests/test_cases/asyncio/check_create_server.py @@ -0,0 +1,26 @@ +import asyncio +import socket + + +async def check_abstract_event_loop(loop: asyncio.AbstractEventLoop, sock: socket.socket) -> None: + await loop.create_server(asyncio.Protocol, None, 8000) + await loop.create_server(asyncio.Protocol, "localhost") + await loop.create_server(asyncio.Protocol, "localhost", None) + await loop.create_server(asyncio.Protocol, "localhost", 8000) + await loop.create_server(asyncio.Protocol, port=8000) + await loop.create_server(asyncio.Protocol, sock=sock) + + await loop.create_server(asyncio.Protocol) # type: ignore + await loop.create_server(asyncio.Protocol, "localhost", sock=sock) # type: ignore + + +async def check_base_event_loop(loop: asyncio.BaseEventLoop, sock: socket.socket) -> None: + await loop.create_server(asyncio.Protocol, None, 8000) + await loop.create_server(asyncio.Protocol, "localhost") + await loop.create_server(asyncio.Protocol, "localhost", None) + await loop.create_server(asyncio.Protocol, "localhost", 8000) + await loop.create_server(asyncio.Protocol, port=8000) + await loop.create_server(asyncio.Protocol, sock=sock) + + await loop.create_server(asyncio.Protocol) # type: ignore + await loop.create_server(asyncio.Protocol, "localhost", sock=sock) # type: ignore diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 056d9a2d36c9..cfd67e252e74 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -243,8 +243,27 @@ class BaseEventLoop(AbstractEventLoop): async def create_server( self, protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = None, - port: int = ..., + host: str | Sequence[str] | None, + port: int, + *, + family: int = 0, + flags: int = 1, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + keep_alive: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: str | Sequence[str], + port: int | None = None, *, family: int = 0, flags: int = 1, @@ -259,6 +278,25 @@ class BaseEventLoop(AbstractEventLoop): start_serving: bool = True, ) -> Server: ... @overload + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: None = None, + *, + port: int, + family: int = 0, + flags: int = 1, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + keep_alive: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload async def create_server( self, protocol_factory: _ProtocolFactory, @@ -267,7 +305,7 @@ class BaseEventLoop(AbstractEventLoop): *, family: int = 0, flags: int = 1, - sock: socket = ..., + sock: socket, backlog: int = 100, ssl: _SSLContext = None, reuse_address: bool | None = None, @@ -282,8 +320,8 @@ class BaseEventLoop(AbstractEventLoop): async def create_server( self, protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = None, - port: int = ..., + host: str | Sequence[str] | None, + port: int, *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, @@ -297,6 +335,42 @@ class BaseEventLoop(AbstractEventLoop): start_serving: bool = True, ) -> Server: ... @overload + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: str | Sequence[str], + port: int | None = None, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: None = None, + *, + port: int, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload async def create_server( self, protocol_factory: _ProtocolFactory, @@ -305,7 +379,7 @@ class BaseEventLoop(AbstractEventLoop): *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, - sock: socket = ..., + sock: socket, backlog: int = 100, ssl: _SSLContext = None, reuse_address: bool | None = None, @@ -319,9 +393,43 @@ class BaseEventLoop(AbstractEventLoop): async def create_server( self, protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = None, - port: int = ..., + host: str | Sequence[str] | None, + port: int, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: str | Sequence[str], + port: int | None = None, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: None = None, *, + port: int, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, sock: None = None, @@ -341,7 +449,7 @@ class BaseEventLoop(AbstractEventLoop): *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, - sock: socket = ..., + sock: socket, backlog: int = 100, ssl: _SSLContext = None, reuse_address: bool | None = None, diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 12978a97679f..0fe244d4015e 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -298,9 +298,49 @@ class AbstractEventLoop: async def create_server( self, protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = None, - port: int = ..., + host: str | Sequence[str] | None, + port: int, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + keep_alive: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + @abstractmethod + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: str | Sequence[str], + port: int | None = None, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + keep_alive: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + @abstractmethod + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: None = None, *, + port: int, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, sock: None = None, @@ -323,7 +363,7 @@ class AbstractEventLoop: *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, - sock: socket = ..., + sock: socket, backlog: int = 100, ssl: _SSLContext = None, reuse_address: bool | None = None, @@ -339,8 +379,8 @@ class AbstractEventLoop: async def create_server( self, protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = None, - port: int = ..., + host: str | Sequence[str] | None, + port: int, *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, @@ -355,6 +395,44 @@ class AbstractEventLoop: ) -> Server: ... @overload @abstractmethod + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: str | Sequence[str], + port: int | None = None, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + @abstractmethod + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: None = None, + *, + port: int, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + ssl_shutdown_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + @abstractmethod async def create_server( self, protocol_factory: _ProtocolFactory, @@ -363,7 +441,7 @@ class AbstractEventLoop: *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, - sock: socket = ..., + sock: socket, backlog: int = 100, ssl: _SSLContext = None, reuse_address: bool | None = None, @@ -378,8 +456,26 @@ class AbstractEventLoop: async def create_server( self, protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = None, - port: int = ..., + host: str | Sequence[str] | None, + port: int, + *, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + @abstractmethod + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: str | Sequence[str], + port: int | None = None, *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, @@ -393,6 +489,24 @@ class AbstractEventLoop: ) -> Server: ... @overload @abstractmethod + async def create_server( + self, + protocol_factory: _ProtocolFactory, + host: None = None, + *, + port: int, + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, + sock: None = None, + backlog: int = 100, + ssl: _SSLContext = None, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + ssl_handshake_timeout: float | None = None, + start_serving: bool = True, + ) -> Server: ... + @overload + @abstractmethod async def create_server( self, protocol_factory: _ProtocolFactory, @@ -401,7 +515,7 @@ class AbstractEventLoop: *, family: int = AddressFamily.AF_UNSPEC, flags: int = AddressInfo.AI_PASSIVE, - sock: socket = ..., + sock: socket, backlog: int = 100, ssl: _SSLContext = None, reuse_address: bool | None = None,