Skip to content

Commit

Permalink
Linting fixes (#7874)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Delete .deepsource.toml

* Delete test_fields.py

* Reintroduce file from accidental deletion

Co-authored-by: ankitdobhal <[email protected]>
  • Loading branch information
tomchristie and powerexploit authored Mar 26, 2021
1 parent f83620d commit 0323d6f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions rest_framework/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ def get_html_context(self):
_divide_with_ceil(self.offset, self.limit)
)

if final < 1:
final = 1
final = max(final, 1)
else:
current = 1
final = 1
Expand Down
8 changes: 4 additions & 4 deletions rest_framework/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ def __init__(self, **kwargs):
self.html_cutoff_text or _(api_settings.HTML_SELECT_CUTOFF_TEXT)
)
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, '
'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, '
'when setting read_only=`True`.'
)
Expand Down Expand Up @@ -339,7 +339,7 @@ def get_url(self, obj, view_name, request, format):
return self.reverse(view_name, kwargs=kwargs, request=request, format=format)

def to_internal_value(self, data):
request = self.context.get('request', None)
request = self.context.get('request')
try:
http_prefix = data.startswith(('http:', 'https:'))
except AttributeError:
Expand Down Expand Up @@ -382,7 +382,7 @@ def to_representation(self, value):
)

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
# unless the target is a different type to the source.
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _supports_form_parsing(self):
'application/x-www-form-urlencoded',
'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):
"""
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get(self, request, *args, **kwargs):
args=args,
kwargs=kwargs,
request=request,
format=kwargs.get('format', None)
format=kwargs.get('format')
)
except NoReverseMatch:
# Don't bail out if eg. no list routes exist, only detail routes.
Expand Down
4 changes: 2 additions & 2 deletions rest_framework/templatetags/rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def format_value(value):
if value is None or isinstance(value, bool):
return mark_safe('<code>%s</code>' % {True: 'true', False: 'false', None: 'null'}[value])
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')
else:
template = loader.get_template('rest_framework/admin/simple_list_value.html')
Expand Down Expand Up @@ -285,7 +285,7 @@ def schema_links(section, sec_key=None):
def add_nested_class(value):
if isinstance(value, dict):
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 ''

Expand Down
2 changes: 1 addition & 1 deletion rest_framework/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CoreAPIClient(coreapi.Client):
def __init__(self, *args, **kwargs):
self._session = RequestsClient()
kwargs['transports'] = [coreapi.transports.HTTPTransport(session=self.session)]
return super().__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

@property
def session(self):
Expand Down

0 comments on commit 0323d6f

Please sign in to comment.