mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +03:00
even more tests
f string modifications
This commit is contained in:
parent
0bb44a8c0f
commit
58b4089595
|
@ -14,8 +14,7 @@ class TokenChangeList(ChangeList):
|
|||
"""Map to matching User id"""
|
||||
def url_for_result(self, result):
|
||||
pk = result.user.pk
|
||||
return reverse('admin:%s_%s_change' % (self.opts.app_label,
|
||||
self.opts.model_name),
|
||||
return reverse(f'admin:{self.opts.app_label}_{self.opts.model_name}_change',
|
||||
args=(quote(pk),),
|
||||
current_app=self.model_admin.admin_site.name)
|
||||
|
||||
|
|
|
@ -1043,7 +1043,7 @@ class DecimalField(Field):
|
|||
if rounding is not None:
|
||||
valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')]
|
||||
assert rounding in valid_roundings, (
|
||||
'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings))
|
||||
f'Invalid rounding option {rounding}. Valid values for rounding are: {valid_roundings}')
|
||||
self.rounding = rounding
|
||||
|
||||
def validate_empty_values(self, data):
|
||||
|
|
|
@ -411,9 +411,9 @@ class HyperlinkedRelatedField(RelatedField):
|
|||
if value in ('', None):
|
||||
value_string = {'': 'the empty string', None: 'None'}[value]
|
||||
msg += (
|
||||
" WARNING: The value of the field on the model instance "
|
||||
"was %s, which may be why it didn't match any "
|
||||
"entries in your URL conf." % value_string
|
||||
f" 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."
|
||||
)
|
||||
raise ImproperlyConfigured(msg % self.view_name)
|
||||
|
||||
|
|
|
@ -967,7 +967,7 @@ class _BaseOpenAPIRenderer:
|
|||
return parameters
|
||||
|
||||
def get_operation(self, link, name, tag):
|
||||
operation_id = "%s_%s" % (tag, name) if tag else name
|
||||
operation_id = f"{tag}_{name}" if tag else name
|
||||
parameters = self.get_parameters(link)
|
||||
|
||||
operation = {
|
||||
|
|
|
@ -158,7 +158,7 @@ def add_query_param(request, key, val):
|
|||
def as_string(value):
|
||||
if value is None:
|
||||
return ''
|
||||
return '%s' % value
|
||||
return f'{value}'
|
||||
|
||||
|
||||
@register.filter
|
||||
|
@ -225,7 +225,7 @@ def format_value(value):
|
|||
elif '@' in value and not re.search(r'\s', value):
|
||||
return mark_safe('<a href="mailto:{value}">{value}</a>'.format(value=escape(value)))
|
||||
elif '\n' in value:
|
||||
return mark_safe('<pre>%s</pre>' % escape(value))
|
||||
return mark_safe(f'<pre>{escape(value)}</pre>')
|
||||
return str(value)
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class ClassLookupDict:
|
|||
hierarchy in method resolution order, and returns the first matching value
|
||||
from the dictionary or raises a KeyError if nothing matches.
|
||||
"""
|
||||
|
||||
def __init__(self, mapping):
|
||||
self.mapping = mapping
|
||||
|
||||
|
@ -37,7 +38,7 @@ class ClassLookupDict:
|
|||
for cls in inspect.getmro(base_class):
|
||||
if cls in self.mapping:
|
||||
return self.mapping[cls]
|
||||
raise KeyError('Class %s not found in lookup.' % base_class.__name__)
|
||||
raise KeyError(f'Class {base_class.__name__} not found in lookup.')
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self.mapping[key] = value
|
||||
|
|
|
@ -53,7 +53,7 @@ def field_repr(field, force_many=False):
|
|||
|
||||
arg_string = ', '.join([smart_repr(val) for val in field._args])
|
||||
kwarg_string = ', '.join([
|
||||
'%s=%s' % (key, smart_repr(val))
|
||||
f'{key}={smart_repr(val)}'
|
||||
for key, val in sorted(kwargs.items())
|
||||
])
|
||||
if arg_string and kwarg_string:
|
||||
|
@ -64,7 +64,7 @@ def field_repr(field, force_many=False):
|
|||
else:
|
||||
class_name = field.__class__.__name__
|
||||
|
||||
return "%s(%s%s)" % (class_name, arg_string, kwarg_string)
|
||||
return f"{class_name}({arg_string}{kwarg_string})"
|
||||
|
||||
|
||||
def serializer_repr(serializer, indent, force_many=None):
|
||||
|
@ -88,8 +88,8 @@ def serializer_repr(serializer, indent, force_many=None):
|
|||
ret += field_repr(field)
|
||||
|
||||
if serializer.validators:
|
||||
ret += '\n' + indent_str + 'class Meta:'
|
||||
ret += '\n' + indent_str + ' validators = ' + smart_repr(serializer.validators)
|
||||
ret += f'\n{indent_str}class Meta:'
|
||||
ret += f'\n{indent_str} validators = {smart_repr(serializer.validators)}'
|
||||
|
||||
return ret
|
||||
|
||||
|
|
|
@ -92,8 +92,7 @@ class ViewSetMixin:
|
|||
f"keyword argument to {cls.__name__}(). Don't do that."
|
||||
)
|
||||
if not hasattr(cls, key):
|
||||
raise TypeError("%s() received an invalid keyword %r" % (
|
||||
cls.__name__, key))
|
||||
raise TypeError(f"{cls.__name__}() received an invalid keyword {key}")
|
||||
|
||||
# name and suffix are mutually exclusive
|
||||
if 'name' in initkwargs and 'suffix' in initkwargs:
|
||||
|
|
Loading…
Reference in New Issue
Block a user