Skip to content

Commit ed16f40

Browse files
committed
pyupgrade changes.
cc @jdufresne
1 parent 6536b7f commit ed16f40

34 files changed

+98
-98
lines changed

rest_framework/authtoken/management/commands/drf_create_token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def handle(self, *args, **options):
3838
token = self.create_user_token(username, reset_token)
3939
except UserModel.DoesNotExist:
4040
raise CommandError(
41-
'Cannot create the Token: user {0} does not exist'.format(
41+
'Cannot create the Token: user {} does not exist'.format(
4242
username)
4343
)
4444
self.stdout.write(
45-
'Generated token {0} for user {1}'.format(token.key, username))
45+
'Generated token {} for user {}'.format(token.key, username))

rest_framework/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ErrorDetail(str):
6868
code = None
6969

7070
def __new__(cls, string, code=None):
71-
self = super(ErrorDetail, cls).__new__(cls, string)
71+
self = super().__new__(cls, string)
7272
self.code = code
7373
return self
7474

rest_framework/fields.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_attribute(instance, attrs):
8888
# If we raised an Attribute or KeyError here it'd get treated
8989
# as an omitted field in `Field.get_attribute()`. Instead we
9090
# raise a ValueError to ensure the exception is not masked.
91-
raise ValueError('Exception raised in callable attribute "{0}"; original exception was: {1}'.format(attr, exc))
91+
raise ValueError('Exception raised in callable attribute "{}"; original exception was: {}'.format(attr, exc))
9292

9393
return instance
9494

@@ -598,7 +598,7 @@ def __new__(cls, *args, **kwargs):
598598
When a field is instantiated, we store the arguments that were used,
599599
so that we can present a helpful representation of the object.
600600
"""
601-
instance = super(Field, cls).__new__(cls)
601+
instance = super().__new__(cls)
602602
instance._args = args
603603
instance._kwargs = kwargs
604604
return instance
@@ -843,7 +843,7 @@ def __init__(self, **kwargs):
843843
if self.uuid_format not in self.valid_formats:
844844
raise ValueError(
845845
'Invalid format for uuid representation. '
846-
'Must be one of "{0}"'.format('", "'.join(self.valid_formats))
846+
'Must be one of "{}"'.format('", "'.join(self.valid_formats))
847847
)
848848
super().__init__(**kwargs)
849849

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

1107-
return '{0:f}'.format(quantized)
1107+
return '{:f}'.format(quantized)
11081108

11091109
def quantize(self, value):
11101110
"""

rest_framework/negotiation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def select_renderer(self, request, renderers, format_suffix=None):
6464
# Accepted media type is 'application/json'
6565
full_media_type = ';'.join(
6666
(renderer.media_type,) +
67-
tuple('{0}={1}'.format(
67+
tuple('{}={}'.format(
6868
key, value.decode(HTTP_HEADER_ENCODING))
6969
for key, value in media_type_wrapper.params.items()))
7070
return renderer, full_media_type

rest_framework/relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __new__(cls, *args, **kwargs):
121121
# `ManyRelatedField` classes instead when `many=True` is set.
122122
if kwargs.pop('many', False):
123123
return cls.many_init(*args, **kwargs)
124-
return super(RelatedField, cls).__new__(cls, *args, **kwargs)
124+
return super().__new__(cls, *args, **kwargs)
125125

126126
@classmethod
127127
def many_init(cls, *args, **kwargs):

rest_framework/response.py

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

6464
if content_type is None and charset is not None:
65-
content_type = "{0}; charset={1}".format(media_type, charset)
65+
content_type = "{}; charset={}".format(media_type, charset)
6666
elif content_type is None:
6767
content_type = media_type
6868
self['Content-Type'] = content_type

rest_framework/schemas/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def handle_exception(self, exc):
3838
self.renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
3939
neg = self.perform_content_negotiation(self.request, force=True)
4040
self.request.accepted_renderer, self.request.accepted_media_type = neg
41-
return super(SchemaView, self).handle_exception(exc)
41+
return super().handle_exception(exc)

rest_framework/serializers.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def __init__(self, instance=None, data=empty, **kwargs):
113113
self.partial = kwargs.pop('partial', False)
114114
self._context = kwargs.pop('context', {})
115115
kwargs.pop('many', None)
116-
super(BaseSerializer, self).__init__(**kwargs)
116+
super().__init__(**kwargs)
117117

118118
def __new__(cls, *args, **kwargs):
119119
# We override this method in order to automagically create
120120
# `ListSerializer` classes instead when `many=True` is set.
121121
if kwargs.pop('many', False):
122122
return cls.many_init(*args, **kwargs)
123-
return super(BaseSerializer, cls).__new__(cls, *args, **kwargs)
123+
return super().__new__(cls, *args, **kwargs)
124124

125125
@classmethod
126126
def many_init(cls, *args, **kwargs):
@@ -313,7 +313,7 @@ def _get_declared_fields(cls, bases, attrs):
313313

314314
def __new__(cls, name, bases, attrs):
315315
attrs['_declared_fields'] = cls._get_declared_fields(bases, attrs)
316-
return super(SerializerMetaclass, cls).__new__(cls, name, bases, attrs)
316+
return super().__new__(cls, name, bases, attrs)
317317

318318

319319
def as_serializer_error(exc):
@@ -463,7 +463,7 @@ def run_validators(self, value):
463463
to_validate.update(value)
464464
else:
465465
to_validate = value
466-
super(Serializer, self).run_validators(to_validate)
466+
super().run_validators(to_validate)
467467

468468
def to_internal_value(self, data):
469469
"""
@@ -557,12 +557,12 @@ def __getitem__(self, key):
557557

558558
@property
559559
def data(self):
560-
ret = super(Serializer, self).data
560+
ret = super().data
561561
return ReturnDict(ret, serializer=self)
562562

563563
@property
564564
def errors(self):
565-
ret = super(Serializer, self).errors
565+
ret = super().errors
566566
if isinstance(ret, list) and len(ret) == 1 and getattr(ret[0], 'code', None) == 'null':
567567
# Edge case. Provide a more descriptive error than
568568
# "this field may not be null", when no data is passed.
@@ -588,11 +588,11 @@ def __init__(self, *args, **kwargs):
588588
self.allow_empty = kwargs.pop('allow_empty', True)
589589
assert self.child is not None, '`child` is a required argument.'
590590
assert not inspect.isclass(self.child), '`child` has not been instantiated.'
591-
super(ListSerializer, self).__init__(*args, **kwargs)
591+
super().__init__(*args, **kwargs)
592592
self.child.bind(field_name='', parent=self)
593593

594594
def bind(self, field_name, parent):
595-
super(ListSerializer, self).bind(field_name, parent)
595+
super().bind(field_name, parent)
596596
self.partial = self.parent.partial
597597

598598
def get_initial(self):
@@ -762,12 +762,12 @@ def __repr__(self):
762762

763763
@property
764764
def data(self):
765-
ret = super(ListSerializer, self).data
765+
ret = super().data
766766
return ReturnList(ret, serializer=self)
767767

768768
@property
769769
def errors(self):
770-
ret = super(ListSerializer, self).errors
770+
ret = super().errors
771771
if isinstance(ret, list) and len(ret) == 1 and getattr(ret[0], 'code', None) == 'null':
772772
# Edge case. Provide a more descriptive error than
773773
# "this field may not be null", when no data is passed.

rest_framework/test.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ def close(self):
104104

105105
class RequestsClient(requests.Session):
106106
def __init__(self, *args, **kwargs):
107-
super(RequestsClient, self).__init__(*args, **kwargs)
107+
super().__init__(*args, **kwargs)
108108
adapter = DjangoTestAdapter()
109109
self.mount('http://', adapter)
110110
self.mount('https://', adapter)
111111

112112
def request(self, method, url, *args, **kwargs):
113113
if not url.startswith('http'):
114114
raise ValueError('Missing "http:" or "https:". Use a fully qualified URL, eg "http://testserver%s"' % url)
115-
return super(RequestsClient, self).request(method, url, *args, **kwargs)
115+
return super().request(method, url, *args, **kwargs)
116116

117117
else:
118118
def RequestsClient(*args, **kwargs):
@@ -124,7 +124,7 @@ class CoreAPIClient(coreapi.Client):
124124
def __init__(self, *args, **kwargs):
125125
self._session = RequestsClient()
126126
kwargs['transports'] = [coreapi.transports.HTTPTransport(session=self.session)]
127-
return super(CoreAPIClient, self).__init__(*args, **kwargs)
127+
return super().__init__(*args, **kwargs)
128128

129129
@property
130130
def session(self):
@@ -144,7 +144,7 @@ def __init__(self, enforce_csrf_checks=False, **defaults):
144144
self.renderer_classes = {}
145145
for cls in self.renderer_classes_list:
146146
self.renderer_classes[cls.format] = cls
147-
super(APIRequestFactory, self).__init__(**defaults)
147+
super().__init__(**defaults)
148148

149149
def _encode_data(self, data, format=None, content_type=None):
150150
"""
@@ -166,7 +166,7 @@ def _encode_data(self, data, format=None, content_type=None):
166166
format = format or self.default_format
167167

168168
assert format in self.renderer_classes, (
169-
"Invalid format '{0}'. Available formats are {1}. "
169+
"Invalid format '{}'. Available formats are {}. "
170170
"Set TEST_REQUEST_RENDERER_CLASSES to enable "
171171
"extra request formats.".format(
172172
format,
@@ -179,7 +179,7 @@ def _encode_data(self, data, format=None, content_type=None):
179179
ret = renderer.render(data)
180180

181181
# Determine the content-type header from the renderer
182-
content_type = "{0}; charset={1}".format(
182+
content_type = "{}; charset={}".format(
183183
renderer.media_type, renderer.charset
184184
)
185185

@@ -228,11 +228,11 @@ def generic(self, method, path, data='',
228228
if content_type is not None:
229229
extra['CONTENT_TYPE'] = str(content_type)
230230

231-
return super(APIRequestFactory, self).generic(
231+
return super().generic(
232232
method, path, data, content_type, secure, **extra)
233233

234234
def request(self, **kwargs):
235-
request = super(APIRequestFactory, self).request(**kwargs)
235+
request = super().request(**kwargs)
236236
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
237237
return request
238238

@@ -246,18 +246,18 @@ class ForceAuthClientHandler(ClientHandler):
246246
def __init__(self, *args, **kwargs):
247247
self._force_user = None
248248
self._force_token = None
249-
super(ForceAuthClientHandler, self).__init__(*args, **kwargs)
249+
super().__init__(*args, **kwargs)
250250

251251
def get_response(self, request):
252252
# This is the simplest place we can hook into to patch the
253253
# request object.
254254
force_authenticate(request, self._force_user, self._force_token)
255-
return super(ForceAuthClientHandler, self).get_response(request)
255+
return super().get_response(request)
256256

257257

258258
class APIClient(APIRequestFactory, DjangoClient):
259259
def __init__(self, enforce_csrf_checks=False, **defaults):
260-
super(APIClient, self).__init__(**defaults)
260+
super().__init__(**defaults)
261261
self.handler = ForceAuthClientHandler(enforce_csrf_checks)
262262
self._credentials = {}
263263

@@ -280,49 +280,49 @@ def force_authenticate(self, user=None, token=None):
280280
def request(self, **kwargs):
281281
# Ensure that any credentials set get added to every request.
282282
kwargs.update(self._credentials)
283-
return super(APIClient, self).request(**kwargs)
283+
return super().request(**kwargs)
284284

285285
def get(self, path, data=None, follow=False, **extra):
286-
response = super(APIClient, self).get(path, data=data, **extra)
286+
response = super().get(path, data=data, **extra)
287287
if follow:
288288
response = self._handle_redirects(response, **extra)
289289
return response
290290

291291
def post(self, path, data=None, format=None, content_type=None,
292292
follow=False, **extra):
293-
response = super(APIClient, self).post(
293+
response = super().post(
294294
path, data=data, format=format, content_type=content_type, **extra)
295295
if follow:
296296
response = self._handle_redirects(response, **extra)
297297
return response
298298

299299
def put(self, path, data=None, format=None, content_type=None,
300300
follow=False, **extra):
301-
response = super(APIClient, self).put(
301+
response = super().put(
302302
path, data=data, format=format, content_type=content_type, **extra)
303303
if follow:
304304
response = self._handle_redirects(response, **extra)
305305
return response
306306

307307
def patch(self, path, data=None, format=None, content_type=None,
308308
follow=False, **extra):
309-
response = super(APIClient, self).patch(
309+
response = super().patch(
310310
path, data=data, format=format, content_type=content_type, **extra)
311311
if follow:
312312
response = self._handle_redirects(response, **extra)
313313
return response
314314

315315
def delete(self, path, data=None, format=None, content_type=None,
316316
follow=False, **extra):
317-
response = super(APIClient, self).delete(
317+
response = super().delete(
318318
path, data=data, format=format, content_type=content_type, **extra)
319319
if follow:
320320
response = self._handle_redirects(response, **extra)
321321
return response
322322

323323
def options(self, path, data=None, format=None, content_type=None,
324324
follow=False, **extra):
325-
response = super(APIClient, self).options(
325+
response = super().options(
326326
path, data=data, format=format, content_type=content_type, **extra)
327327
if follow:
328328
response = self._handle_redirects(response, **extra)
@@ -336,7 +336,7 @@ def logout(self):
336336
self.handler._force_token = None
337337

338338
if self.session:
339-
super(APIClient, self).logout()
339+
super().logout()
340340

341341

342342
class APITransactionTestCase(testcases.TransactionTestCase):
@@ -383,11 +383,11 @@ def setUpClass(cls):
383383
cls._module.urlpatterns = cls.urlpatterns
384384

385385
cls._override.enable()
386-
super(URLPatternsTestCase, cls).setUpClass()
386+
super().setUpClass()
387387

388388
@classmethod
389389
def tearDownClass(cls):
390-
super(URLPatternsTestCase, cls).tearDownClass()
390+
super().tearDownClass()
391391
cls._override.disable()
392392

393393
if hasattr(cls, '_module_urlpatterns'):

rest_framework/throttling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def allow_request(self, request, view):
230230
self.num_requests, self.duration = self.parse_rate(self.rate)
231231

232232
# We can now proceed as normal.
233-
return super(ScopedRateThrottle, self).allow_request(request, view)
233+
return super().allow_request(request, view)
234234

235235
def get_cache_key(self, request, view):
236236
"""

0 commit comments

Comments
 (0)