diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 15b50af0b..af6247c5e 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -149,7 +149,7 @@ def to_choices_dict(choices): # choices = [('Category', ((1, 'First'), (2, 'Second'))), (3, 'Third')] ret = OrderedDict() for choice in choices: - if (not isinstance(choice, (list, tuple))): + if not isinstance(choice, (list, tuple)): # single choice ret[choice] = choice else: diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 8ccdc342c..6d05a5462 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -131,7 +131,7 @@ def _reverse_ordering(ordering_tuple): ordering and return a new tuple, eg. `('created', '-uuid')`. """ def invert(x): - return x[1:] if (x.startswith('-')) else '-' + x + return x[1:] if x.startswith('-') else '-' + x return tuple([invert(item) for item in ordering_tuple]) diff --git a/rest_framework/relations.py b/rest_framework/relations.py index c1898d0d8..eac9647b0 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -503,7 +503,7 @@ class ManyRelatedField(Field): return [] relationship = get_attribute(instance, self.source_attrs) - return relationship.all() if (hasattr(relationship, 'all')) else relationship + return relationship.all() if hasattr(relationship, 'all') else relationship def to_representation(self, iterable): return [ diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 97984daf9..97dab8741 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -540,7 +540,7 @@ class BrowsableAPIRenderer(BaseRenderer): # If possible, serialize the initial content for the generic form default_parser = view.parser_classes[0] renderer_class = getattr(default_parser, 'renderer_class', None) - if (hasattr(view, 'get_serializer') and renderer_class): + if hasattr(view, 'get_serializer') and renderer_class: # View has a serializer defined and parser class has a # corresponding renderer that can be used to render the data. @@ -598,7 +598,7 @@ class BrowsableAPIRenderer(BaseRenderer): paginator = getattr(view, 'paginator', None) if isinstance(data, list): pass - elif (paginator is not None and data is not None): + elif paginator is not None and data is not None: try: paginator.get_results(data) except (TypeError, KeyError): @@ -738,7 +738,7 @@ class AdminRenderer(BrowsableAPIRenderer): ret = template_render(template, context, request=renderer_context['request']) # Creation and deletion should use redirects in the admin style. - if (response.status_code == status.HTTP_201_CREATED) and ('Location' in response): + if response.status_code == status.HTTP_201_CREATED and 'Location' in response: response.status_code = status.HTTP_303_SEE_OTHER response['Location'] = request.build_absolute_uri() ret = '' @@ -764,7 +764,7 @@ class AdminRenderer(BrowsableAPIRenderer): ) paginator = getattr(context['view'], 'paginator', None) - if (paginator is not None and data is not None): + if paginator is not None and data is not None: try: results = paginator.get_results(data) except (TypeError, KeyError): diff --git a/rest_framework/request.py b/rest_framework/request.py index 7121689d2..b4bd2d020 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -152,7 +152,7 @@ class Request(object): force_user = getattr(request, '_force_auth_user', None) force_token = getattr(request, '_force_auth_token', None) - if (force_user is not None or force_token is not None): + if force_user is not None or force_token is not None: forced_auth = ForcedAuthentication(force_user, force_token) self.authenticators = (forced_auth,) diff --git a/rest_framework/versioning.py b/rest_framework/versioning.py index e5524afe8..5c9a7ade1 100644 --- a/rest_framework/versioning.py +++ b/rest_framework/versioning.py @@ -117,7 +117,7 @@ class NamespaceVersioning(BaseVersioning): def determine_version(self, request, *args, **kwargs): resolver_match = getattr(request, 'resolver_match', None) - if (resolver_match is None or not resolver_match.namespace): + if resolver_match is None or not resolver_match.namespace: return self.default_version # Allow for possibly nested namespaces.