From ed8aa343f6c1290de50e4c000197e2b68bf0b53d Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Wed, 4 Nov 2020 16:59:53 +0000 Subject: [PATCH] #184: Fix misc. linting issues --- .../common/filter_order_handler.py | 39 ++++++++----------- datagateway_api/common/helpers.py | 4 +- datagateway_api/common/icat/helpers.py | 2 +- .../src/swagger/apispec_flask_restful.py | 2 +- util/icat_db_generator.py | 4 +- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/datagateway_api/common/filter_order_handler.py b/datagateway_api/common/filter_order_handler.py index da283043..01254da8 100644 --- a/datagateway_api/common/filter_order_handler.py +++ b/datagateway_api/common/filter_order_handler.py @@ -50,29 +50,22 @@ def merge_python_icat_limit_skip_filters(self): limit filter and remove the skip filter from the instance """ log.info("Merging a PythonICATSkipFilter and PythonICATLimitFilter together") - - if any( - isinstance(icat_filter, PythonICATSkipFilter) - for icat_filter in self.filters - ) and any( - isinstance(icat_filter, PythonICATLimitFilter) - for icat_filter in self.filters - ): - # Merge skip and limit filter into a single limit filter - for icat_filter in self.filters: - if isinstance(icat_filter, PythonICATSkipFilter): - skip_filter = icat_filter - request_skip_value = icat_filter.skip_value - - if isinstance(icat_filter, PythonICATLimitFilter): - limit_filter = icat_filter - - if skip_filter and limit_filter: - log.info("Merging skip filter with limit filter") - limit_filter.skip_value = skip_filter.skip_value - log.info("Removing skip filter from list of filters") - self.remove_filter(skip_filter) - log.debug("Filters: %s", self.filters) + skip_filter = None + limit_filter = None + + for icat_filter in self.filters: + if isinstance(icat_filter, PythonICATSkipFilter): + skip_filter = icat_filter + + if isinstance(icat_filter, PythonICATLimitFilter): + limit_filter = icat_filter + + if skip_filter and limit_filter: + log.info("Merging skip filter with limit filter") + limit_filter.skip_value = skip_filter.skip_value + log.info("Removing skip filter from list of filters") + self.remove_filter(skip_filter) + log.debug("Filters: %s", self.filters) def clear_python_icat_order_filters(self): """ diff --git a/datagateway_api/common/helpers.py b/datagateway_api/common/helpers.py index 4ef7b8bc..7c6a3a3f 100644 --- a/datagateway_api/common/helpers.py +++ b/datagateway_api/common/helpers.py @@ -59,7 +59,7 @@ def get_session_id_from_auth_header(): args["Authorization"].split(" ") if args["Authorization"] is not None else "" ) if auth_header == "": - raise MissingCredentialsError(f"No credentials provided in auth header") + raise MissingCredentialsError("No credentials provided in auth header") if len(auth_header) != 2 or auth_header[0] != "Bearer": raise AuthenticationError( f" Could not authenticate consumer with auth header {auth_header}", @@ -74,7 +74,7 @@ def is_valid_json(string): :return: boolean representing if the string is valid JSON """ try: - json_object = json.loads(string) + json.loads(string) except ValueError: return False except TypeError: diff --git a/datagateway_api/common/icat/helpers.py b/datagateway_api/common/icat/helpers.py index e56d659e..8bb090b3 100644 --- a/datagateway_api/common/icat/helpers.py +++ b/datagateway_api/common/icat/helpers.py @@ -210,7 +210,7 @@ def get_entity_by_id( # Set query condition for the selected ID id_condition = PythonICATWhereFilter.create_condition("id", "=", id_) - includes_value = "1" if return_related_entities == True else None + includes_value = "1" if return_related_entities else None id_query = ICATQuery( client, entity_type, conditions=id_condition, includes=includes_value, ) diff --git a/datagateway_api/src/swagger/apispec_flask_restful.py b/datagateway_api/src/swagger/apispec_flask_restful.py index 8573b0f8..b43b8559 100644 --- a/datagateway_api/src/swagger/apispec_flask_restful.py +++ b/datagateway_api/src/swagger/apispec_flask_restful.py @@ -61,7 +61,7 @@ def parse_operations(resource, operations): logging.getLogger(__name__).warning( "Cannot load docstring for {}/{}".format(resource, method), ) - operations[method.lower()] = operation or dict() + operations[method.lower()] = operation or {} class RestfulPlugin(apispec.BasePlugin): diff --git a/util/icat_db_generator.py b/util/icat_db_generator.py index a1585d49..4e53007d 100644 --- a/util/icat_db_generator.py +++ b/util/icat_db_generator.py @@ -695,8 +695,8 @@ def generate_all(i, generators): def main(): start_time = datetime.datetime.now() generators = [generator() for generator in Generator.__subclasses__()] - TIERS = 7 - for i in range(TIERS): + tiers = 7 + for i in range(tiers): generate_all(i, generators) print(