Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix run_app typing (#4957) #5114

Merged
merged 2 commits into from
Oct 24, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGES/4957.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix run_app typing
19 changes: 16 additions & 3 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
from argparse import ArgumentParser
from collections.abc import Iterable
from importlib import import_module
from typing import Any, Awaitable, Callable, List, Optional, Set, Type, Union, cast
from typing import (
Any as Any,
Awaitable as Awaitable,
Callable as Callable,
Iterable as TypingIterable,
List as List,
Optional as Optional,
Set as Set,
Type as Type,
Union as Union,
cast as cast,
)

from .abc import AbstractAccessLogger
from .helpers import all_tasks
Expand Down Expand Up @@ -270,11 +281,13 @@
except ImportError: # pragma: no cover
SSLContext = Any # type: ignore

HostSequence = TypingIterable[str]


async def _run_app(
app: Union[Application, Awaitable[Application]],
*,
host: Optional[str] = None,
host: Optional[Union[str, HostSequence]] = None,
port: Optional[int] = None,
path: Optional[str] = None,
sock: Optional[socket.socket] = None,
Expand Down Expand Up @@ -448,7 +461,7 @@ def run_app(
app: Union[Application, Awaitable[Application]],
*,
debug: bool = False,
host: Optional[str] = None,
host: Optional[Union[str, HostSequence]] = None,
port: Optional[int] = None,
path: Optional[str] = None,
sock: Optional[socket.socket] = None,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,27 @@ def test_run_app_nondefault_host_port(patched_loop, aiohttp_unused_port) -> None
)


def test_run_app_multiple_hosts(patched_loop) -> None:
hosts = ("127.0.0.1", "127.0.0.2")

app = web.Application()
web.run_app(app, host=hosts, print=stopper(patched_loop))

calls = map(
lambda h: mock.call(
mock.ANY,
h,
8080,
ssl=None,
backlog=128,
reuse_address=None,
reuse_port=None,
),
hosts,
)
patched_loop.create_server.assert_has_calls(calls)


def test_run_app_custom_backlog(patched_loop) -> None:
app = web.Application()
web.run_app(app, backlog=10, print=stopper(patched_loop))
Expand Down