Skip to content

Commit

Permalink
fix run_app typing (#4957) (#5114)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Svetlov <[email protected]>
  • Loading branch information
derlih and asvetlov committed Oct 24, 2020
1 parent 274cade commit 8d135d8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
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 @@ -447,7 +460,7 @@ def _cancel_tasks(
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
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

0 comments on commit 8d135d8

Please sign in to comment.