mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-24 10:34:03 +03:00
Linting fixes (#7874)
* Fixed code quality issues - Added '.deepsource.toml' file for continuous analysis on bug risk - Remove `return` from `__init__()` method - Remove duplicate dictionary key(s) - Use `max` built-in to get the maximum of two values - Remove redundant `None` default - Remove unnecessary comprehension Signed-off-by: ankitdobhal <dobhal.ankit@protonmail.com> * Delete .deepsource.toml * Delete test_fields.py * Reintroduce file from accidental deletion Co-authored-by: ankitdobhal <dobhal.ankit@protonmail.com>
This commit is contained in:
parent
f83620dcc9
commit
0323d6f895
|
@ -488,8 +488,7 @@ class LimitOffsetPagination(BasePagination):
|
||||||
_divide_with_ceil(self.offset, self.limit)
|
_divide_with_ceil(self.offset, self.limit)
|
||||||
)
|
)
|
||||||
|
|
||||||
if final < 1:
|
final = max(final, 1)
|
||||||
final = 1
|
|
||||||
else:
|
else:
|
||||||
current = 1
|
current = 1
|
||||||
final = 1
|
final = 1
|
||||||
|
|
|
@ -104,11 +104,11 @@ class RelatedField(Field):
|
||||||
self.html_cutoff_text or _(api_settings.HTML_SELECT_CUTOFF_TEXT)
|
self.html_cutoff_text or _(api_settings.HTML_SELECT_CUTOFF_TEXT)
|
||||||
)
|
)
|
||||||
if not method_overridden('get_queryset', RelatedField, self):
|
if not method_overridden('get_queryset', RelatedField, self):
|
||||||
assert self.queryset is not None or kwargs.get('read_only', None), (
|
assert self.queryset is not None or kwargs.get('read_only'), (
|
||||||
'Relational field must provide a `queryset` argument, '
|
'Relational field must provide a `queryset` argument, '
|
||||||
'override `get_queryset`, or set read_only=`True`.'
|
'override `get_queryset`, or set read_only=`True`.'
|
||||||
)
|
)
|
||||||
assert not (self.queryset is not None and kwargs.get('read_only', None)), (
|
assert not (self.queryset is not None and kwargs.get('read_only')), (
|
||||||
'Relational fields should not provide a `queryset` argument, '
|
'Relational fields should not provide a `queryset` argument, '
|
||||||
'when setting read_only=`True`.'
|
'when setting read_only=`True`.'
|
||||||
)
|
)
|
||||||
|
@ -339,7 +339,7 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
return self.reverse(view_name, kwargs=kwargs, request=request, format=format)
|
return self.reverse(view_name, kwargs=kwargs, request=request, format=format)
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
request = self.context.get('request', None)
|
request = self.context.get('request')
|
||||||
try:
|
try:
|
||||||
http_prefix = data.startswith(('http:', 'https:'))
|
http_prefix = data.startswith(('http:', 'https:'))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -382,7 +382,7 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
)
|
)
|
||||||
|
|
||||||
request = self.context['request']
|
request = self.context['request']
|
||||||
format = self.context.get('format', None)
|
format = self.context.get('format')
|
||||||
|
|
||||||
# By default use whatever format is given for the current context
|
# By default use whatever format is given for the current context
|
||||||
# unless the target is a different type to the source.
|
# unless the target is a different type to the source.
|
||||||
|
|
|
@ -316,7 +316,7 @@ class Request:
|
||||||
'application/x-www-form-urlencoded',
|
'application/x-www-form-urlencoded',
|
||||||
'multipart/form-data'
|
'multipart/form-data'
|
||||||
)
|
)
|
||||||
return any([parser.media_type in form_media for parser in self.parsers])
|
return any(parser.media_type in form_media for parser in self.parsers)
|
||||||
|
|
||||||
def _parse(self):
|
def _parse(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -290,7 +290,7 @@ class APIRootView(views.APIView):
|
||||||
args=args,
|
args=args,
|
||||||
kwargs=kwargs,
|
kwargs=kwargs,
|
||||||
request=request,
|
request=request,
|
||||||
format=kwargs.get('format', None)
|
format=kwargs.get('format')
|
||||||
)
|
)
|
||||||
except NoReverseMatch:
|
except NoReverseMatch:
|
||||||
# Don't bail out if eg. no list routes exist, only detail routes.
|
# Don't bail out if eg. no list routes exist, only detail routes.
|
||||||
|
|
|
@ -206,7 +206,7 @@ def format_value(value):
|
||||||
if value is None or isinstance(value, bool):
|
if value is None or isinstance(value, bool):
|
||||||
return mark_safe('<code>%s</code>' % {True: 'true', False: 'false', None: 'null'}[value])
|
return mark_safe('<code>%s</code>' % {True: 'true', False: 'false', None: 'null'}[value])
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
if any([isinstance(item, (list, dict)) for item in value]):
|
if any(isinstance(item, (list, dict)) for item in value):
|
||||||
template = loader.get_template('rest_framework/admin/list_value.html')
|
template = loader.get_template('rest_framework/admin/list_value.html')
|
||||||
else:
|
else:
|
||||||
template = loader.get_template('rest_framework/admin/simple_list_value.html')
|
template = loader.get_template('rest_framework/admin/simple_list_value.html')
|
||||||
|
@ -285,7 +285,7 @@ def schema_links(section, sec_key=None):
|
||||||
def add_nested_class(value):
|
def add_nested_class(value):
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
return 'class=nested'
|
return 'class=nested'
|
||||||
if isinstance(value, list) and any([isinstance(item, (list, dict)) for item in value]):
|
if isinstance(value, list) and any(isinstance(item, (list, dict)) for item in value):
|
||||||
return 'class=nested'
|
return 'class=nested'
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ if coreapi is not None:
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._session = RequestsClient()
|
self._session = RequestsClient()
|
||||||
kwargs['transports'] = [coreapi.transports.HTTPTransport(session=self.session)]
|
kwargs['transports'] = [coreapi.transports.HTTPTransport(session=self.session)]
|
||||||
return super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self):
|
def session(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user