Skip to content

Commit ea1da76

Browse files
authored
Add pyupgrade to pre-commit hooks (#9682)
1 parent 2fbfaae commit ea1da76

21 files changed

+47
-41
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ repos:
3131
hooks:
3232
- id: codespell
3333
exclude: locale|kickstarter-announcement.md|coreapi-0.1.1.js
34+
35+
- repo: https://github.com/asottile/pyupgrade
36+
rev: v3.19.1
37+
hooks:
38+
- id: pyupgrade
39+
args: ["--py39-plus", "--keep-percent-format"]

rest_framework/authtoken/management/commands/drf_create_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def handle(self, *args, **options):
4242
username)
4343
)
4444
self.stdout.write(
45-
'Generated token {} for user {}'.format(token.key, username))
45+
f'Generated token {token.key} for user {username}')

rest_framework/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_attribute(instance, attrs):
111111
# If we raised an Attribute or KeyError here it'd get treated
112112
# as an omitted field in `Field.get_attribute()`. Instead we
113113
# raise a ValueError to ensure the exception is not masked.
114-
raise ValueError('Exception raised in callable attribute "{}"; original exception was: {}'.format(attr, exc))
114+
raise ValueError(f'Exception raised in callable attribute "{attr}"; original exception was: {exc}')
115115

116116
return instance
117117

@@ -1103,7 +1103,7 @@ def to_representation(self, value):
11031103
if self.localize:
11041104
return localize_input(quantized)
11051105

1106-
return '{:f}'.format(quantized)
1106+
return f'{quantized:f}'
11071107

11081108
def quantize(self, value):
11091109
"""
@@ -1861,7 +1861,7 @@ def __init__(self, method_name=None, **kwargs):
18611861
def bind(self, field_name, parent):
18621862
# The method name defaults to `get_{field_name}`.
18631863
if self.method_name is None:
1864-
self.method_name = 'get_{field_name}'.format(field_name=field_name)
1864+
self.method_name = f'get_{field_name}'
18651865

18661866
super().bind(field_name, parent)
18671867

rest_framework/negotiation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def select_renderer(self, request, renderers, format_suffix=None):
6565
full_media_type = ';'.join(
6666
(renderer.media_type,) +
6767
tuple(
68-
'{}={}'.format(key, value)
68+
f'{key}={value}'
6969
for key, value in media_type_wrapper.params.items()
7070
)
7171
)

rest_framework/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _queryset(self, view):
225225
if hasattr(view, 'get_queryset'):
226226
queryset = view.get_queryset()
227227
assert queryset is not None, (
228-
'{}.get_queryset() returned None'.format(view.__class__.__name__)
228+
f'{view.__class__.__name__}.get_queryset() returned None'
229229
)
230230
return queryset
231231
return view.queryset

rest_framework/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def rendered_content(self):
6666
content_type = self.content_type
6767

6868
if content_type is None and charset is not None:
69-
content_type = "{}; charset={}".format(media_type, charset)
69+
content_type = f"{media_type}; charset={charset}"
7070
elif content_type is None:
7171
content_type = media_type
7272
self['Content-Type'] = content_type

rest_framework/schemas/coreapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_available_key(self, preferred_key):
6868
current_val = self.methods_counter[preferred_key]
6969
self.methods_counter[preferred_key] += 1
7070

71-
key = '{}_{}'.format(preferred_key, current_val)
71+
key = f'{preferred_key}_{current_val}'
7272
if key not in self:
7373
return key
7474

rest_framework/schemas/openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_schema(self, request=None, public=False):
8282
continue
8383
if components_schemas[k] == components[k]:
8484
continue
85-
warnings.warn('Schema component "{}" has been overridden with a different value.'.format(k))
85+
warnings.warn(f'Schema component "{k}" has been overridden with a different value.')
8686

8787
components_schemas.update(components)
8888

@@ -644,7 +644,7 @@ def get_response_serializer(self, path, method):
644644
return self.get_serializer(path, method)
645645

646646
def get_reference(self, serializer):
647-
return {'$ref': '#/components/schemas/{}'.format(self.get_component_name(serializer))}
647+
return {'$ref': f'#/components/schemas/{self.get_component_name(serializer)}'}
648648

649649
def get_request_body(self, path, method):
650650
if method not in ('PUT', 'PATCH', 'POST'):

rest_framework/utils/field_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def get_unique_validators(field_name, model_field):
6666
"""
6767
Returns a list of UniqueValidators that should be applied to the field.
6868
"""
69-
field_set = set([field_name])
69+
field_set = {field_name}
7070
conditions = {
7171
c.condition
7272
for c in model_field.model._meta.constraints

tests/schemas/test_coreapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ def _verify_cbv_links(self, loc, url, methods=None, suffixes=None):
12341234

12351235
for method, suffix in zip(methods, suffixes):
12361236
if suffix is not None:
1237-
key = '{}_{}'.format(method, suffix)
1237+
key = f'{method}_{suffix}'
12381238
else:
12391239
key = method
12401240
assert loc[key].url == url

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy