You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BaseEventLoop.create_server overload doesn't allow passing host with port=None #16157
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:
importasyncioasyncdefstart():
loop=asyncio.get_running_loop()
awaitloop.create_server(asyncio.Protocol)
awaitloop.create_server(asyncio.Protocol, 'localhost')
awaitloop.create_server(asyncio.Protocol, 'localhost', 8080)
awaitloop.create_server(asyncio.Protocol, 'localhost')
awaitloop.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.
This doesn't make sense indeed. The reason for the two overloads is probably to ensure that exactly one of host/port and sock are specified. We just need a third overload (..., host: str | Sequence[str], port: int | None = None, ..., sock: None = None, ...) and the need to remove the default to port in the existing overload.
This is also one of the rare cases where having tests seems useful.
I took a closer look at the three version-specific overload sets and won't be able to complete this within my current small-change window. Releasing it for someone else—sorry for the noise.
Activity
srittau commentedon Aug 7, 2026
This doesn't make sense indeed. The reason for the two overloads is probably to ensure that exactly one of
host/portandsockare specified. We just need a third overload (..., host: str | Sequence[str], port: int | None = None, ..., sock: None = None, ...) and the need to remove the default toportin the existing overload.This is also one of the rare cases where having tests seems useful.
PR welcome!
nightcityblade commentedon Aug 9, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
nightcityblade commentedon Aug 9, 2026
I took a closer look at the three version-specific overload sets and won't be able to complete this within my current small-change window. Releasing it for someone else—sorry for the noise.