Browse Source

ref(pyupgrade): more f-strings (#23933)

josh 4 years ago
parent
commit
8c10aba03d

+ 1 - 1
examples/oauth2_consumer_webserver/app.py

@@ -53,7 +53,7 @@ def index():
             # Unauthorized - bad token
             session.pop("access_token", None)
             return redirect(url_for("login"))
-        return "{}\n{}".format(str(e), e.read())
+        return f"{e}\n{e.read()}"
 
     return ("<h1>Hi, {}!</h1>" "<pre>{}</pre>").format(
         json.loads(session["user"])["email"], json.dumps(json.loads(res.read()), indent=2)

+ 5 - 5
setup.py

@@ -3,15 +3,15 @@
 import os
 import sys
 
-version = sys.version_info
+python_version = sys.version_info[:2]
 
-if version[:2] < (3, 6):
-    sys.exit("Error: Sentry requires at least Python 3.6 ({})".format(version[:2]))
-if version[:2] > (3, 6):
+if python_version < (3, 6):
+    sys.exit(f"Error: Sentry requires at least Python 3.6 ({python_version})")
+if python_version > (3, 6):
     import logging
 
     logger = logging.getLogger()
-    logger.warning("A Python version different than 3.6 is being used ({})".format(version[:2]))
+    logger.warning(f"A Python version different than 3.6 is being used ({python_version})")
 
 
 from distutils.command.build import build as BuildCommand

+ 1 - 1
src/bitfield/types.py

@@ -137,7 +137,7 @@ class BitHandler:
     def __repr__(self):
         return "<{}: {}>".format(
             self.__class__.__name__,
-            ", ".join("{}={}".format(k, self.get_bit(n).is_set) for n, k in enumerate(self._keys)),
+            ", ".join(f"{k}={self.get_bit(n).is_set}" for n, k in enumerate(self._keys)),
         )
 
     def __str__(self):

+ 2 - 4
src/sentry/api/base.py

@@ -96,9 +96,7 @@ class Endpoint(APIView):
 
     def build_cursor_link(self, request, name, cursor):
         querystring = "&".join(
-            "{}={}".format(urlquote(k), urlquote(v))
-            for k, v in request.GET.items()
-            if k != "cursor"
+            f"{urlquote(k)}={urlquote(v)}" for k, v in request.GET.items() if k != "cursor"
         )
         base_url = absolute_uri(urlquote(request.path))
         if querystring:
@@ -229,7 +227,7 @@ class Endpoint(APIView):
 
             with sentry_sdk.start_span(
                 op="base.dispatch.execute",
-                description="{}.{}".format(type(self).__name__, handler.__name__),
+                description=f"{type(self).__name__}.{handler.__name__}",
             ):
                 response = handler(request, *args, **kwargs)
 

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

@@ -154,7 +154,7 @@ class OrganizationEventsV2EndpointBase(OrganizationEventsEndpointBase):
         # The base API function only uses the last query parameter, but this endpoint
         # needs all the parameters, particularly for the "field" query param.
         querystring = "&".join(
-            "{}={}".format(urlquote(query[0]), urlquote(value))
+            f"{urlquote(query[0])}={urlquote(value)}"
             for query in request.GET.lists()
             if query[0] != "cursor"
             for value in query[1]

+ 1 - 1
src/sentry/api/endpoints/organization_details.py

@@ -331,7 +331,7 @@ class OrganizationSerializer(serializers.Serializer):
                 )
 
                 if self.initial_data[key] != default_value:
-                    changed_data[key] = "to {}".format(self.initial_data[key])
+                    changed_data[key] = f"to {self.initial_data[key]}"
             else:
                 option_inst.value = self.initial_data[key]
                 # check if ORG_OPTIONS changed

+ 1 - 1
src/sentry/api/endpoints/project_users.py

@@ -30,7 +30,7 @@ class ProjectUsersEndpoint(ProjectEndpoint):
                 return Response([])
             try:
                 queryset = queryset.filter(
-                    **{"{}__icontains".format(EventUser.attr_from_keyword(pieces[0])): pieces[1]}
+                    **{f"{EventUser.attr_from_keyword(pieces[0])}__icontains": pieces[1]}
                 )
             except KeyError:
                 return Response([])

+ 3 - 3
src/sentry/api/event_search.py

@@ -1040,7 +1040,7 @@ def convert_condition_to_function(cond):
     function = OPERATOR_TO_FUNCTION.get(cond[1])
     if not function:
         # It's hard to make this error more specific without exposing internals to the end user
-        raise InvalidSearchQuery("Operator {} is not a valid condition operator.".format(cond[1]))
+        raise InvalidSearchQuery(f"Operator {cond[1]} is not a valid condition operator.")
 
     return [function, [cond[0], cond[2]]]
 
@@ -1904,7 +1904,7 @@ class Function:
     def validate_result_type(self, result_type):
         assert (
             result_type is None or result_type in RESULT_TYPES
-        ), "{}: result type {} not one of {}".format(self.name, result_type, list(RESULT_TYPES))
+        ), f"{self.name}: result type {result_type} not one of {list(RESULT_TYPES)}"
 
     def is_accessible(self, acl=None):
         if not self.private:
@@ -2730,7 +2730,7 @@ def resolve_field_list(
                             field=column,
                             function_msg=", ".join(conflicting_functions[:2])
                             + (
-                                " and {} more.".format(len(conflicting_functions) - 2)
+                                f" and {len(conflicting_functions) - 2} more."
                                 if len(conflicting_functions) > 2
                                 else ""
                             ),

+ 2 - 2
src/sentry/api/helpers/group_index.py

@@ -97,7 +97,7 @@ def build_query_params_from_request(request, organization, projects, environment
                 parse_search_query(query), projects, request.user, environments
             )
         except InvalidSearchQuery as e:
-            raise ValidationError("Your search query could not be parsed: {}".format(str(e)))
+            raise ValidationError(f"Your search query could not be parsed: {e}")
 
         validate_search_filter_permissions(organization, search_filters, request.user)
         query_kwargs["search_filters"] = search_filters
@@ -473,7 +473,7 @@ def rate_limit_endpoint(limit=1, window=1):
         def wrapper(self, request, *args, **kwargs):
             ip = request.META["REMOTE_ADDR"]
             if ratelimiter.is_limited(
-                "rate_limit_endpoint:{}:{}".format(md5_text(function).hexdigest(), ip),
+                f"rate_limit_endpoint:{md5_text(function).hexdigest()}:{ip}",
                 limit=limit,
                 window=window,
             ):

+ 1 - 1
src/sentry/api/serializers/snuba.py

@@ -14,7 +14,7 @@ HEALTH_ID_KEY = "_health_id"
 def make_health_id(lookup, value):
     # Convert a lookup and value into
     # a string that can be used back in a request query.
-    return "{}:{}".format(lookup.name, lookup.encoder(value))
+    return f"{lookup.name}:{lookup.encoder(value)}"
 
 
 def serialize_releases(organization, item_list, user, lookup):

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