Browse Source

ref(pyupgrade): f-strings, partition 3 (#23707)

josh 4 years ago
parent
commit
9ff0cb34a8

+ 3 - 5
src/sentry/api/base.py

@@ -102,7 +102,7 @@ class Endpoint(APIView):
         )
         base_url = absolute_uri(urlquote(request.path))
         if querystring:
-            base_url = "{}?{}".format(base_url, querystring)
+            base_url = f"{base_url}?{querystring}"
         else:
             base_url = base_url + "?"
 
@@ -207,7 +207,7 @@ class Endpoint(APIView):
                 if origin and request.auth:
                     allowed_origins = request.auth.get_allowed_origins()
                     if not is_valid_origin(origin, allowed=allowed_origins):
-                        response = Response("Invalid origin: %s" % (origin,), status=400)
+                        response = Response(f"Invalid origin: {origin}", status=400)
                         self.response = self.finalize_response(request, response, *args, **kwargs)
                         return self.response
 
@@ -281,9 +281,7 @@ class Endpoint(APIView):
 
         max_per_page = max(max_per_page, default_per_page)
         if per_page > max_per_page:
-            raise ParseError(
-                detail="Invalid per_page value. Cannot exceed {}.".format(max_per_page)
-            )
+            raise ParseError(detail=f"Invalid per_page value. Cannot exceed {max_per_page}.")
 
         return per_page
 

+ 1 - 1
src/sentry/api/bases/avatar.py

@@ -38,7 +38,7 @@ class AvatarMixin:
         return {"type": self.model, "kwargs": {self.object_type: obj}}
 
     def get_avatar_filename(self, obj):
-        return "{}.png".format(obj.id)
+        return f"{obj.id}.png"
 
     def put(self, request, **kwargs):
         obj = kwargs[self.object_type]

+ 1 - 1
src/sentry/api/bases/organization.py

@@ -290,7 +290,7 @@ class OrganizationEndpoint(Endpoint):
                     grouped_period = "<=30d"
                 sentry_sdk.set_tag("query.period.grouped", grouped_period)
         except InvalidParams as e:
-            raise ParseError(detail="Invalid date range: {}".format(e))
+            raise ParseError(detail=f"Invalid date range: {e}")
 
         try:
             projects = self.get_projects(request, organization, project_ids)

+ 2 - 4
src/sentry/api/bases/organization_events.py

@@ -41,9 +41,7 @@ class OrganizationEventsEndpointBase(OrganizationEndpoint):
         with sentry_sdk.start_span(op="discover.endpoint", description="filter_params"):
             if len(request.GET.getlist("field")) > MAX_FIELDS:
                 raise ParseError(
-                    detail="You can view up to {} fields at a time. Please delete some and try again.".format(
-                        MAX_FIELDS
-                    )
+                    detail=f"You can view up to {MAX_FIELDS} fields at a time. Please delete some and try again."
                 )
 
             params = self.get_filter_params(request, organization)
@@ -164,7 +162,7 @@ class OrganizationEventsV2EndpointBase(OrganizationEventsEndpointBase):
 
         base_url = absolute_uri(urlquote(request.path))
         if querystring:
-            base_url = "{}?{}".format(base_url, querystring)
+            base_url = f"{base_url}?{querystring}"
         else:
             base_url = base_url + "?"
 

+ 2 - 2
src/sentry/api/bases/project.py

@@ -142,8 +142,8 @@ class ProjectEndpoint(Endpoint):
                 # get full path so that we keep query strings
                 requested_url = request.get_full_path()
                 new_url = requested_url.replace(
-                    "projects/%s/%s/" % (organization_slug, project_slug),
-                    "projects/%s/%s/" % (organization_slug, redirect.project.slug),
+                    f"projects/{organization_slug}/{project_slug}/",
+                    f"projects/{organization_slug}/{redirect.project.slug}/",
                 )
 
                 # Resource was moved/renamed if the requested url is different than the new url

+ 6 - 10
src/sentry/api/bases/sentryapps.py

@@ -113,22 +113,18 @@ class SentryAppsBaseEndpoint(IntegrationPlatformEndpoint):
         try:
             return Organization.objects.get(slug=organization_slug)
         except Organization.DoesNotExist:
-            error_message = """
-                Organization '{}' does not exist.
-            """.format(
-                organization_slug
-            )
+            error_message = f"""
+                Organization '{organization_slug}' does not exist.
+            """
             raise ValidationError({"organization": to_single_line_str(error_message)})
 
     def _get_organization_for_user(self, user, organization_slug):
         try:
             return user.get_orgs().get(slug=organization_slug)
         except Organization.DoesNotExist:
-            error_message = """
-                User does not belong to the '{}' organization.
-            """.format(
-                organization_slug
-            )
+            error_message = f"""
+                User does not belong to the '{organization_slug}' organization.
+            """
             raise PermissionDenied(to_single_line_str(error_message))
 
     def _get_organization(self, request):

+ 2 - 2
src/sentry/api/client.py

@@ -13,10 +13,10 @@ class ApiError(Exception):
         self.body = body
 
     def __str__(self):
-        return "status={} body={}".format(self.status_code, self.body)
+        return f"status={self.status_code} body={self.body}"
 
     def __repr__(self):
-        return "<ApiError: {}>".format(self)
+        return f"<ApiError: {self}>"
 
 
 class ApiClient:

+ 2 - 2
src/sentry/api/endpoints/debug_files.py

@@ -84,7 +84,7 @@ class DebugFilesEndpoint(ProjectEndpoint):
     def download(self, debug_file_id, project):
         rate_limited = ratelimits.is_limited(
             project=project,
-            key="rl:DSymFilesEndpoint:download:%s:%s" % (debug_file_id, project.id),
+            key=f"rl:DSymFilesEndpoint:download:{debug_file_id}:{project.id}",
             limit=10,
         )
         if rate_limited:
@@ -105,7 +105,7 @@ class DebugFilesEndpoint(ProjectEndpoint):
                 iter(lambda: fp.read(4096), b""), content_type="application/octet-stream"
             )
             response["Content-Length"] = debug_file.file.size
-            response["Content-Disposition"] = 'attachment; filename="%s%s"' % (
+            response["Content-Disposition"] = 'attachment; filename="{}{}"'.format(
                 posixpath.basename(debug_file.debug_id),
                 debug_file.file_extension,
             )

+ 1 - 3
src/sentry/api/endpoints/group_details.py

@@ -309,9 +309,7 @@ class GroupDetailsEndpoint(GroupEndpoint, EnvironmentMixin):
             # TODO(dcramer): we need to implement assignedTo in the bulk mutation
             # endpoint
             response = client.put(
-                path="/projects/{}/{}/issues/".format(
-                    group.project.organization.slug, group.project.slug
-                ),
+                path=f"/projects/{group.project.organization.slug}/{group.project.slug}/issues/",
                 params={"id": group.id},
                 data=request.data,
                 request=request,

+ 1 - 3
src/sentry/api/endpoints/group_events_latest.py

@@ -24,9 +24,7 @@ class GroupEventsLatestEndpoint(GroupEndpoint):
 
         try:
             return client.get(
-                "/projects/{}/{}/events/{}/".format(
-                    event.organization.slug, event.project.slug, event.event_id
-                ),
+                f"/projects/{event.organization.slug}/{event.project.slug}/events/{event.event_id}/",
                 request=request,
                 data={"environment": environments},
             )

Some files were not shown because too many files changed in this diff