diff --git a/starlette/applications.py b/starlette/applications.py index 7a2093c27a..344a4a37fe 100644 --- a/starlette/applications.py +++ b/starlette/applications.py @@ -111,7 +111,7 @@ def build_middleware_stack(self) -> ASGIApp: def routes(self) -> typing.List[BaseRoute]: return self.router.routes - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: return self.router.url_path_for(name, **path_params) async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: diff --git a/starlette/requests.py b/starlette/requests.py index b422a943b8..fff451e232 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -173,7 +173,7 @@ def state(self) -> State: self._state = State(self.scope["state"]) return self._state - def url_for(self, /, name: str, **path_params: typing.Any) -> URL: + def url_for(self, name: str, /, **path_params: typing.Any) -> URL: router: Router = self.scope["router"] url_path = router.url_path_for(name, **path_params) return url_path.make_absolute_url(base_url=self.base_url) diff --git a/starlette/routing.py b/starlette/routing.py index 5251977a73..b50d32a1fc 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -179,7 +179,7 @@ class BaseRoute: def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: raise NotImplementedError() # pragma: no cover - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: raise NotImplementedError() # pragma: no cover async def handle(self, scope: Scope, receive: Receive, send: Send) -> None: @@ -258,7 +258,7 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: return Match.FULL, child_scope return Match.NONE, {} - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: seen_params = set(path_params.keys()) expected_params = set(self.param_convertors.keys()) @@ -333,7 +333,7 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: return Match.FULL, child_scope return Match.NONE, {} - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: seen_params = set(path_params.keys()) expected_params = set(self.param_convertors.keys()) @@ -415,7 +415,7 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: return Match.FULL, child_scope return Match.NONE, {} - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: if self.name is not None and name == self.name and "path" in path_params: # 'name' matches "". path_params["path"] = path_params["path"].lstrip("/") @@ -493,7 +493,7 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: return Match.FULL, child_scope return Match.NONE, {} - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: if self.name is not None and name == self.name and "path" in path_params: # 'name' matches "". path = path_params.pop("path") @@ -652,7 +652,7 @@ async def not_found(self, scope: Scope, receive: Receive, send: Send) -> None: response = PlainTextResponse("Not Found", status_code=404) await response(scope, receive, send) - def url_path_for(self, /, name: str, **path_params: typing.Any) -> URLPath: + def url_path_for(self, name: str, /, **path_params: typing.Any) -> URLPath: for route in self.routes: try: return route.url_path_for(name, **path_params) diff --git a/starlette/templating.py b/starlette/templating.py index 817ed9fae8..cd95011df2 100644 --- a/starlette/templating.py +++ b/starlette/templating.py @@ -123,7 +123,7 @@ def _create_env( **env_options: typing.Any, ) -> "jinja2.Environment": @pass_context - def url_for(context: dict, /, name: str, **path_params: typing.Any) -> URL: + def url_for(context: dict, name: str, /, **path_params: typing.Any) -> URL: request = context["request"] return request.url_for(name, **path_params)