The type stubs for BaseEventLoop.create_server (here) consist over two overloads:
# The first one specifies:
host: str | Sequence[str] | None = None,
port: int = ...,
sock: None = None,
# The second one specifies:
host: None = None,
port: None = None,
sock: socket = ...,
But the first of these causes a typing error if you pass None for the port (pyright playground), despite succeeding at runtime:
import asyncio
async def start():
loop = asyncio.get_running_loop()
await loop.create_server(asyncio.Protocol)
await loop.create_server(asyncio.Protocol, 'localhost')
await loop.create_server(asyncio.Protocol, 'localhost', 8080)
await loop.create_server(asyncio.Protocol, 'localhost')
await loop.create_server(asyncio.Protocol, 'localhost', None) # Argument of type "None" cannot be assigned to parameter "port" of type "int" in function "create_server".
This is documented as being valid as far back as Python 3.9. For some reason the 3.8 and earlier docs don't provide any details for the port parameter, though I'm not aware of any changes.
The type stubs for
BaseEventLoop.create_server(here) consist over two overloads:But the first of these causes a typing error if you pass None for the port (pyright playground), despite succeeding at runtime:
This is documented as being valid as far back as Python 3.9. For some reason the 3.8 and earlier docs don't provide any details for the port parameter, though I'm not aware of any changes.