Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions stdlib/@tests/test_cases/asyncio/check_create_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations

import asyncio
import socket
from typing_extensions import assert_type


async def check_create_server(loop: asyncio.AbstractEventLoop, base_loop: asyncio.BaseEventLoop) -> None:
# `port` is optional whenever a host is given: the runtime passes it straight
# to getaddrinfo, which treats None as "any port".
assert_type(await loop.create_server(asyncio.Protocol, "localhost"), asyncio.Server)
assert_type(await loop.create_server(asyncio.Protocol, "localhost", 8080), asyncio.Server)
assert_type(await loop.create_server(asyncio.Protocol, "localhost", None), asyncio.Server)
assert_type(await loop.create_server(asyncio.Protocol, ["localhost", "127.0.0.1"], 8080), asyncio.Server)

# A port with no host binds every interface.
assert_type(await loop.create_server(asyncio.Protocol, None, 8080), asyncio.Server)
assert_type(await loop.create_server(asyncio.Protocol, port=8080), asyncio.Server)

assert_type(await base_loop.create_server(asyncio.Protocol, "localhost", None), asyncio.Server)
assert_type(await base_loop.create_server(asyncio.Protocol, port=8080), asyncio.Server)


async def check_create_server_sock(loop: asyncio.AbstractEventLoop, sock: socket.socket) -> None:
assert_type(await loop.create_server(asyncio.Protocol, sock=sock), asyncio.Server)

# The runtime rejects host/port together with sock:
# ValueError: host/port and sock can not be specified at the same time
await loop.create_server(asyncio.Protocol, "localhost", sock=sock) # type: ignore
await loop.create_server(asyncio.Protocol, None, 8080, sock=sock) # type: ignore
6 changes: 3 additions & 3 deletions stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class BaseEventLoop(AbstractEventLoop):
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = None,
port: int = ...,
port: int | None = None,
*,
family: int = 0,
flags: int = 1,
Expand Down Expand Up @@ -283,7 +283,7 @@ class BaseEventLoop(AbstractEventLoop):
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = None,
port: int = ...,
port: int | None = None,
*,
family: int = AddressFamily.AF_UNSPEC,
flags: int = AddressInfo.AI_PASSIVE,
Expand Down Expand Up @@ -320,7 +320,7 @@ class BaseEventLoop(AbstractEventLoop):
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = None,
port: int = ...,
port: int | None = None,
*,
family: int = AddressFamily.AF_UNSPEC,
flags: int = AddressInfo.AI_PASSIVE,
Expand Down
6 changes: 3 additions & 3 deletions stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class AbstractEventLoop:
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = None,
port: int = ...,
port: int | None = None,
*,
family: int = AddressFamily.AF_UNSPEC,
flags: int = AddressInfo.AI_PASSIVE,
Expand Down Expand Up @@ -340,7 +340,7 @@ class AbstractEventLoop:
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = None,
port: int = ...,
port: int | None = None,
*,
family: int = AddressFamily.AF_UNSPEC,
flags: int = AddressInfo.AI_PASSIVE,
Expand Down Expand Up @@ -379,7 +379,7 @@ class AbstractEventLoop:
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = None,
port: int = ...,
port: int | None = None,
*,
family: int = AddressFamily.AF_UNSPEC,
flags: int = AddressInfo.AI_PASSIVE,
Expand Down