From bc71ad6d737f29a46d0a199638db2eea3ad6f71d Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 26 Aug 2021 03:32:55 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Carol Willing --- jupyterhub/apihandlers/users.py | 2 +- jupyterhub/handlers/base.py | 2 +- jupyterhub/objects.py | 4 +++- jupyterhub/orm.py | 4 +--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jupyterhub/apihandlers/users.py b/jupyterhub/apihandlers/users.py index bc12db6c..fb480df8 100644 --- a/jupyterhub/apihandlers/users.py +++ b/jupyterhub/apihandlers/users.py @@ -210,7 +210,7 @@ class UserListAPIHandler(APIHandler): except Exception as e: self.log.error("Failed to create user: %s" % name, exc_info=True) self.users.delete(user) - raise web.HTTPError(400, f"Failed to create user {name}: {str(e)}") + raise web.HTTPError(400, f"Failed to create user {name}: {e}") else: created.append(user) diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 822440fa..7654d5b5 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -623,7 +623,7 @@ class BaseHandler(RequestHandler): if (next_url + '/').startswith( ( f'{self.request.protocol}://{self.request.host}/', - '//%s/' % self.request.host, + f'//{self.request.host}/', ) ) or ( self.subdomain_host diff --git a/jupyterhub/objects.py b/jupyterhub/objects.py index b6857b0b..f5893a3e 100644 --- a/jupyterhub/objects.py +++ b/jupyterhub/objects.py @@ -148,7 +148,9 @@ class Server(HasTraits): def host(self): if self.connect_url: parsed = urlparse(self.connect_url) - return f"{parsed.scheme}://{parsed.netloc}" + proto = parsed.scheme + host = parsed.netloc + return f"{proto}://{host}" if ':' in self._connect_ip: fmt = "{proto}://[{ip}]:{port}" diff --git a/jupyterhub/orm.py b/jupyterhub/orm.py index 903c544c..c368bce4 100644 --- a/jupyterhub/orm.py +++ b/jupyterhub/orm.py @@ -1039,8 +1039,6 @@ def get_class(resource_name): } if resource_name not in class_dict: raise ValueError( - "Kind must be one of {}, not {}".format( - ", ".join(class_dict), resource_name - ) + f'Kind must be one of {", ".join(class_dict)}, not {resource_name}' ) return class_dict[resource_name]