From d258e5791e21e4e67d2b973c177728f63b9de837 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 20 Sep 2023 01:43:40 +0100 Subject: [PATCH] Fix new E721 errors from ruff 0.0.290 --- lib/galaxy/config/__init__.py | 4 ++-- lib/galaxy/jobs/__init__.py | 8 ++++---- lib/galaxy/selenium/navigates_galaxy.py | 2 +- lib/galaxy/tools/actions/upload_common.py | 2 +- lib/galaxy/tools/parameters/basic.py | 2 +- lib/galaxy/webapps/galaxy/api/workflows.py | 2 +- lib/galaxy/workflow/resources/__init__.py | 4 ++-- lib/tool_shed/webapp/api/repositories.py | 2 +- scripts/api/common.py | 8 ++++---- tools/data_source/upload.py | 2 +- tools/stats/gsummary.py | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/galaxy/config/__init__.py b/lib/galaxy/config/__init__.py index e6a381a64da3..0c94373a5f98 100644 --- a/lib/galaxy/config/__init__.py +++ b/lib/galaxy/config/__init__.py @@ -517,7 +517,7 @@ def resolve(key): for key in self.schema.paths_to_resolve: value = getattr(self, key) # Check if value is a list or should be listified; if so, listify and resolve each item separately. - if type(value) is list or (self.listify_options and key in self.listify_options): + if isinstance(value, list) or (self.listify_options and key in self.listify_options): saved_values = listify(getattr(self, key), do_strip=True) # listify and save original value setattr(self, key, "_") # replace value with temporary placeholder resolve(key) # resolve temporary value (`_` becomes `parent-path/_`) @@ -546,7 +546,7 @@ def get_path(current_path, initial_path): return current_path current_value = getattr(self, key) # resolved path or list of resolved paths - if type(current_value) is list: + if isinstance(current_value, list): initial_paths = listify(self._raw_config[key], do_strip=True) # initial unresolved paths updated_paths = [] # check and, if needed, update each path in the list diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 59d6d74fd603..aebe134af744 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -903,24 +903,24 @@ def get_job_runner_plugins(self, handler_id): return rval def is_id(self, collection): - """Given a collection of handlers or destinations, indicate whether the collection represents a tag or a real ID + """Given a collection of handlers or destinations, indicate whether the collection represents a real ID :param collection: A representation of a destination or handler :type collection: tuple or list :returns: bool """ - return type(collection) == tuple + return isinstance(collection, tuple) def is_tag(self, collection): - """Given a collection of handlers or destinations, indicate whether the collection represents a tag or a real ID + """Given a collection of handlers or destinations, indicate whether the collection represents a tag :param collection: A representation of a destination or handler :type collection: tuple or list :returns: bool """ - return type(collection) == list + return isinstance(collection, list) def convert_legacy_destinations(self, job_runners): """Converts legacy (from a URL) destinations to contain the appropriate runner params defined in the URL. diff --git a/lib/galaxy/selenium/navigates_galaxy.py b/lib/galaxy/selenium/navigates_galaxy.py index 71764955fa4d..398e53abaabc 100644 --- a/lib/galaxy/selenium/navigates_galaxy.py +++ b/lib/galaxy/selenium/navigates_galaxy.py @@ -2028,7 +2028,7 @@ def assert_success_message(self, contains=None): def assert_message(self, element, contains=None): if contains is not None: - if type(element) == list: + if isinstance(element, list): assert any( contains in el.text for el in element ), f"{contains} was not found in {[el.text for el in element]}" diff --git a/lib/galaxy/tools/actions/upload_common.py b/lib/galaxy/tools/actions/upload_common.py index 14e4861a9ad8..391b9b4a5ee1 100644 --- a/lib/galaxy/tools/actions/upload_common.py +++ b/lib/galaxy/tools/actions/upload_common.py @@ -55,7 +55,7 @@ def persist_uploads(params, trans): local_filename = util.mkstemp_ln(f.file.name, "upload_file_data_") f.file.close() upload_dataset["file_data"] = dict(filename=f.filename, local_filename=local_filename) - elif type(f) == dict and "local_filename" not in f: + elif isinstance(f, dict) and "local_filename" not in f: raise Exception("Uploaded file was encoded in a way not understood by Galaxy.") if ( "url_paste" in upload_dataset diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 6e16f7fc597c..a4cc61d5f66c 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -659,7 +659,7 @@ def from_json(self, value, trans=None, other_values=None): if isinstance(value, FilesPayload): # multi-part upload handled and persisted in service layer return value.dict() - if type(value) == dict: + elif isinstance(value, dict): if "session_id" in value: # handle api upload session_id = value["session_id"] diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index dc3713100660..f3f94d81fda9 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -150,7 +150,7 @@ def set_workflow_menu(self, trans: GalaxyWebTransaction, payload=None, **kwd): workflow_ids = payload.get("workflow_ids") if workflow_ids is None: workflow_ids = [] - elif type(workflow_ids) != list: + elif not isinstance(workflow_ids, list): workflow_ids = [workflow_ids] workflow_ids_decoded = [] # Decode the encoded workflow ids diff --git a/lib/galaxy/workflow/resources/__init__.py b/lib/galaxy/workflow/resources/__init__.py index 29df790a05b3..d81e85d6e6c4 100644 --- a/lib/galaxy/workflow/resources/__init__.py +++ b/lib/galaxy/workflow/resources/__init__.py @@ -70,7 +70,7 @@ def _resource_parameters_by_group(trans, **kwds): for group_name, group_def in by_group.get("groups", {}).items(): if group_name == default_group or group_name in user_groups: for tag in group_def: - if type(tag) is dict: + if isinstance(tag, dict): if tag.get("name") not in user_permissions: user_permissions[tag.get("name")] = {} for option in tag.get("options"): @@ -131,7 +131,7 @@ def validate_by_group_workflow_parameters_mapper(by_group, workflow_resource_par ) for group in by_group["groups"]: for attrib in by_group["groups"][group]: - if type(attrib) is dict: + if isinstance(attrib, dict): if "name" not in attrib: raise Exception( "'workflow_resource_params_mapper' YAML file is malformed, " diff --git a/lib/tool_shed/webapp/api/repositories.py b/lib/tool_shed/webapp/api/repositories.py index 21c0249e4d5b..c5d3806e2b02 100644 --- a/lib/tool_shed/webapp/api/repositories.py +++ b/lib/tool_shed/webapp/api/repositories.py @@ -1041,7 +1041,7 @@ def create_changeset_revision(self, trans, id, payload, **kwd): local_filename = util.mkstemp_ln(file_data.file.name, "upload_file_data_") file_data.file.close() file_data = dict(filename=file_data.filename, local_filename=local_filename) - elif type(file_data) == dict and "local_filename" not in file_data: + elif isinstance(file_data, dict) and "local_filename" not in file_data: raise Exception("Uploaded file was encoded in a way not understood.") commit_message = kwd.get("commit_message", "Uploaded") diff --git a/scripts/api/common.py b/scripts/api/common.py index 1b5a09e44070..9dca44f367fb 100644 --- a/scripts/api/common.py +++ b/scripts/api/common.py @@ -81,7 +81,7 @@ def display(api_key, url, return_formatted=True): sys.exit(1) if not return_formatted: return r - elif type(r) == list: + elif isinstance(r, list): # Response is a collection as defined in the REST style. print("Collection Members") print("------------------") @@ -103,7 +103,7 @@ def display(api_key, url, return_formatted=True): print(item) print("") print("%d element(s) in collection" % len(r)) - elif type(r) == dict: + elif isinstance(r, dict): # Response is an element as defined in the REST style. print("Member Information") print("------------------") @@ -133,11 +133,11 @@ def submit(api_key, url, data, return_formatted=True): return r print("Response") print("--------") - if type(r) == list: + if isinstance(r, list): # Currently the only implemented responses are lists of dicts, because # submission creates some number of collection elements. for i in r: - if type(i) == dict: + if isinstance(i, dict): if "url" in i: print(i.pop("url")) else: diff --git a/tools/data_source/upload.py b/tools/data_source/upload.py index 97b493dc5b06..704db36b7ca7 100644 --- a/tools/data_source/upload.py +++ b/tools/data_source/upload.py @@ -283,7 +283,7 @@ def __read_paramfile(path): with open(path) as fh: obj = load(fh) # If there's a single dataset in an old-style paramfile it'll still parse, but it'll be a dict - assert type(obj) == list + assert isinstance(obj, list) return obj diff --git a/tools/stats/gsummary.py b/tools/stats/gsummary.py index 868b5d49cb20..3c164d6f1a7d 100755 --- a/tools/stats/gsummary.py +++ b/tools/stats/gsummary.py @@ -176,7 +176,7 @@ def main(): stop_err("Computation resulted in the following error: %s" % str(s)) summary = summary.as_py(BASIC_CONVERSION) outfile.write("#%s\n" % headings_str) - if type(summary) is dict: + if isinstance(summary, dict): # using rpy outfile.write("%s\n" % "\t".join("%g" % summary[k] for k in headings)) else: