BaseEventLoop.create_server overload doesn't allow passing host with port=None
stubs: false positivetopic: asynciohelp wanted
The type stubs for `BaseEventLoop.create_server` ([here](https://github.com/python/typeshed/blob/main/stdlib/asyncio/base_events.pyi#L242)) consist over two overloads:
```py
# 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](https://pyright-play.net/?code=JYWwDg9gTgLgBAQwM4E8B2BjYEBQPnoZwAmApgGZxIwKwAUAlAFw5xtwA2EEYcAvIlSZsAOgDmpGAH0oAVzRpgaMVK49GedogDuCYPDVgRGKKQQxSUpKSgA3G3QLCIIgApQIMCBggcGrdgRdfU5uIxMzCysbeyhHISwXd09vXwAaOAByLgwEDgALCGpM-y0gvQMw41NzS2s7BydEtw8vHw4M7O88wuKMgA4ABiHSwODKnmrIupjGhNFktvSsnJ6imBKAtnKQwyna6Ia4poXW1I6V7oL1zIyAOQg0UgY4AGI4AEEoMVkQUjR4BBKDAUGBSHAAEQPJ4QuC5BSeOAAI3ByCQwDET2IcC8cDAtAQfwsUEhkFgsKBONB4IhShgsKUcHI8gwMGwaEhEQO9ViEJEOCAA)), despite succeeding at runtime:
```py
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](https://docs.python.org/3.9/library/asyncio-eventloop.html#asyncio.loop.create_server) 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.
1 条评论