Skip to content

run_app has incorrect typingΒ #4957

Closed
Closed
@iawells

Description

🐞 Describe the bug

async def _run_app(app: Union[Application, Awaitable[Application]], *,
                   host: Optional[str]=None,

The documentation is a bit woolly:

"host (str) – TCP/IP host or a sequence of hosts for HTTP server. Default is '0.0.0.0' if port has been specified or if path is not supplied."

('(str)' excludes 'None' and excludes 'a sequence of hosts'. Also, I don't think you mean 'sequence' literally.)

But it's clear from reading the code that an iterable of strings is planned for (along with several other types).

I would think you want Optional[Union[str, Iterable[str]]] - though given the following code it's maybe unclear if you think other types are also acceptable.

πŸ’‘ To Reproduce

Write some code like this and then run it though mypy

from aiohttp.web import run_app

hosts: List[str] = ['a', 'b']

run_app(host=hosts)

πŸ’‘ Expected behavior

If a list of strings is acceptable, then the attribute is wrong. I'm surprised mypy didn't spot it during CI, actually.

πŸ“‹ Your version of the Python

$ python --version
Python 3.6.9

πŸ“‹ Your version of the aiohttp/yarl/multidict distributions

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.6.2
$ python -m pip show multidict
Name: multidict
Version: 4.7.6
$ python -m pip show yarl
Name: yarl
Version: 1.5.1

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions