Skip to content

Commit

Permalink
grab routes in __init__ and remove _user_app
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Jan 10, 2022
1 parent b58f0c3 commit e9ff903
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions starlette/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ def __eq__(self, other: typing.Any) -> bool:


class Mount(BaseRoute):
_routes: typing.List[BaseRoute]

def __init__(
self,
path: str,
Expand All @@ -348,9 +350,10 @@ def __init__(
self.path = path.rstrip("/")
if app is not None:
self.app: ASGIApp = app
self._routes = getattr(app, "routes", [])
else:
self.app = Router(routes=routes)
self._user_app = self.app
self._routes = getattr(self.app, "routes", [])
self.name = name
self.path_regex, self.path_format, self.param_convertors = compile_path(
self.path + "/{path:path}"
Expand All @@ -362,9 +365,7 @@ def __init__(

@property
def routes(self) -> typing.List[BaseRoute]:
# we dynamically grab the routes so that if this is a Starlette router
# it can have routes added to it after it is mounted
return getattr(self._user_app, "routes", [])
return self._routes

def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]:
if scope["type"] in ("http", "websocket"):
Expand Down

0 comments on commit e9ff903

Please sign in to comment.