diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 91da73de6..dc120d8e8 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -488,8 +488,7 @@ class LimitOffsetPagination(BasePagination): _divide_with_ceil(self.offset, self.limit) ) - if final < 1: - final = 1 + final = max(final, 1) else: current = 1 final = 1 diff --git a/rest_framework/relations.py b/rest_framework/relations.py index cbdf23369..c98700784 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -104,11 +104,11 @@ class RelatedField(Field): 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`.' ) @@ -339,7 +339,7 @@ class HyperlinkedRelatedField(RelatedField): 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: @@ -382,7 +382,7 @@ class HyperlinkedRelatedField(RelatedField): ) 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. diff --git a/rest_framework/request.py b/rest_framework/request.py index 2a007cd2b..17ceadb08 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -316,7 +316,7 @@ class Request: '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): """ diff --git a/rest_framework/routers.py b/rest_framework/routers.py index e2afa573f..e0ae24b95 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -290,7 +290,7 @@ class APIRootView(views.APIView): 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. diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 7bfa8f599..db0e9c95c 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -206,7 +206,7 @@ def format_value(value): if value is None or isinstance(value, bool): return mark_safe('%s' % {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') @@ -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 '' diff --git a/rest_framework/test.py b/rest_framework/test.py index 8ab0f2de1..e934eff55 100644 --- a/rest_framework/test.py +++ b/rest_framework/test.py @@ -124,7 +124,7 @@ if coreapi is not None: 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):