From dca1b5bc0e97d2e50e810bf6ed3bdd77ba53528d Mon Sep 17 00:00:00 2001 From: Jeremy Langley Date: Sun, 20 Feb 2022 08:48:26 -0800 Subject: [PATCH] speed ups Less f strings needed for non-modified strings and one indentation speedup fixed. --- rest_framework/authtoken/admin.py | 1 + rest_framework/filters.py | 2 +- rest_framework/relations.py | 4 ++-- rest_framework/serializers.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rest_framework/authtoken/admin.py b/rest_framework/authtoken/admin.py index 262dd0873..4596d7cd9 100644 --- a/rest_framework/authtoken/admin.py +++ b/rest_framework/authtoken/admin.py @@ -12,6 +12,7 @@ User = get_user_model() class TokenChangeList(ChangeList): """Map to matching User id""" + def url_for_result(self, result): pk = result.user.pk return reverse(f'admin:{self.opts.app_label}_{self.opts.model_name}_change', diff --git a/rest_framework/filters.py b/rest_framework/filters.py index f83596bbf..31fcf283f 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -296,7 +296,7 @@ class OrderingFilter(BaseFilterBackend): for key, label in self.get_valid_fields(queryset, view, context): options.append((key, f'{label} - {_("ascending")}')) options.append(('-' + key, f'{label} - {_("descending")}')) - context['options'] = options + context['options'] = options return context def to_html(self, request, queryset, view): diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 7dfdd3b88..3de6a6385 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -411,9 +411,9 @@ class HyperlinkedRelatedField(RelatedField): if value in ('', None): value_string = {'': 'the empty string', None: 'None'}[value] msg += ( - f" WARNING: The value of the field on the model instance " + " WARNING: The value of the field on the model instance " f"was {value_string}, which may be why it didn't match any " - f"entries in your URL conf." + "entries in your URL conf." ) raise ImproperlyConfigured(msg % self.view_name) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 48747e687..ac4b92ca8 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -1114,7 +1114,7 @@ class ModelSerializer(Serializer): ) assert not (fields and exclude), ( - f"Cannot set both 'fields' and 'exclude' options on " + "Cannot set both 'fields' and 'exclude' options on " f"serializer {self.__class__.__name__}." )