diff --git a/scripts/lint b/scripts/lint index a0830195..eceead71 100755 --- a/scripts/lint +++ b/scripts/lint @@ -7,6 +7,7 @@ fi set -x +${PREFIX}mypy starlette --ignore-missing-imports --disallow-untyped-defs ${PREFIX}autoflake --in-place --recursive starlette tests ${PREFIX}black starlette tests ${PREFIX}isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply starlette tests diff --git a/starlette/routing.py b/starlette/routing.py index 2a63fcd6..9fa29794 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -276,10 +276,23 @@ class WebSocketRoute(BaseRoute): class Mount(BaseRoute): - def __init__(self, path: str, app: ASGIApp, name: str = None) -> None: + def __init__( + self, + path: str, + app: ASGIApp = None, + routes: typing.List[BaseRoute] = None, + name: str = None, + ) -> None: assert path == "" or path.startswith("/"), "Routed paths must start with '/'" + assert ( + app is not None or routes is not None + ), "Either 'app', or 'routes' must be specified" self.path = path.rstrip("/") - self.app = app + if routes is None: + assert app is not None + self.app = app + else: + self.app = Router(routes=routes) self.name = name self.path_regex, self.path_format, self.param_convertors = compile_path( path + "/{path:path}" diff --git a/tests/test_routing.py b/tests/test_routing.py index 900d561d..68c379aa 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -38,14 +38,12 @@ app = Router( Route("/", endpoint=homepage, methods=["GET"]), Mount( "/users", - app=Router( - [ - Route("/", endpoint=users), - Route("/me", endpoint=user_me), - Route("/{username}", endpoint=user), - Route("/nomatch", endpoint=user_no_match), - ] - ), + routes=[ + Route("/", endpoint=users), + Route("/me", endpoint=user_me), + Route("/{username}", endpoint=user), + Route("/nomatch", endpoint=user_no_match), + ], ), Mount("/static", app=staticfiles), ]