From 3ace6955307559227d1d9b7a67f5eedc45c26729 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Tue, 20 Jun 2023 07:49:04 +0200 Subject: [PATCH] Rename __name to name --- starlette/applications.py | 4 ++-- starlette/requests.py | 4 ++-- starlette/routing.py | 44 +++++++++++++++++++-------------------- starlette/templating.py | 4 ++-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/starlette/applications.py b/starlette/applications.py index ce7203404..7a2093c27 100644 --- a/starlette/applications.py +++ b/starlette/applications.py @@ -111,8 +111,8 @@ 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: - return self.router.url_path_for(__name, **path_params) + 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: scope["app"] = self diff --git a/starlette/requests.py b/starlette/requests.py index 010d0d7d6..b422a943b 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -173,9 +173,9 @@ 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) + 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 fa5beaff1..5251977a7 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,12 +258,12 @@ 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()) - if __name != self.name or seen_params != expected_params: - raise NoMatchFound(__name, path_params) + if name != self.name or seen_params != expected_params: + raise NoMatchFound(name, path_params) path, remaining_params = replace_params( self.path_format, self.param_convertors, path_params @@ -333,12 +333,12 @@ 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()) - if __name != self.name or seen_params != expected_params: - raise NoMatchFound(__name, path_params) + if name != self.name or seen_params != expected_params: + raise NoMatchFound(name, path_params) path, remaining_params = replace_params( self.path_format, self.param_convertors, path_params @@ -415,8 +415,8 @@ 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: - if self.name is not None and __name == self.name and "path" in path_params: + 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("/") path, remaining_params = replace_params( @@ -424,13 +424,13 @@ def url_path_for(self, /, __name: str, **path_params: typing.Any) -> URLPath: ) if not remaining_params: return URLPath(path=path) - elif self.name is None or __name.startswith(self.name + ":"): + elif self.name is None or name.startswith(self.name + ":"): if self.name is None: # No mount name. - remaining_name = __name + remaining_name = name else: # 'name' matches ":". - remaining_name = __name[len(self.name) + 1 :] + remaining_name = name[len(self.name) + 1 :] path_kwarg = path_params.get("path") path_params["path"] = "" path_prefix, remaining_params = replace_params( @@ -446,7 +446,7 @@ def url_path_for(self, /, __name: str, **path_params: typing.Any) -> URLPath: ) except NoMatchFound: pass - raise NoMatchFound(__name, path_params) + raise NoMatchFound(name, path_params) async def handle(self, scope: Scope, receive: Receive, send: Send) -> None: await self.app(scope, receive, send) @@ -493,8 +493,8 @@ 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: - if self.name is not None and __name == self.name and "path" in path_params: + 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") host, remaining_params = replace_params( @@ -502,13 +502,13 @@ def url_path_for(self, /, __name: str, **path_params: typing.Any) -> URLPath: ) if not remaining_params: return URLPath(path=path, host=host) - elif self.name is None or __name.startswith(self.name + ":"): + elif self.name is None or name.startswith(self.name + ":"): if self.name is None: # No mount name. - remaining_name = __name + remaining_name = name else: # 'name' matches ":". - remaining_name = __name[len(self.name) + 1 :] + remaining_name = name[len(self.name) + 1 :] host, remaining_params = replace_params( self.host_format, self.param_convertors, path_params ) @@ -518,7 +518,7 @@ def url_path_for(self, /, __name: str, **path_params: typing.Any) -> URLPath: return URLPath(path=str(url), protocol=url.protocol, host=host) except NoMatchFound: pass - raise NoMatchFound(__name, path_params) + raise NoMatchFound(name, path_params) async def handle(self, scope: Scope, receive: Receive, send: Send) -> None: await self.app(scope, receive, send) @@ -652,13 +652,13 @@ 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) + return route.url_path_for(name, **path_params) except NoMatchFound: pass - raise NoMatchFound(__name, path_params) + raise NoMatchFound(name, path_params) async def startup(self) -> None: """ diff --git a/starlette/templating.py b/starlette/templating.py index 8e7fae212..817ed9fae 100644 --- a/starlette/templating.py +++ b/starlette/templating.py @@ -123,9 +123,9 @@ 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) + return request.url_for(name, **path_params) loader = jinja2.FileSystemLoader(directory) env_options.setdefault("loader", loader)