From 92f23aaa95b276e133e99fef03e7f025385e16ed Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sat, 9 Mar 2024 19:27:27 +0000 Subject: [PATCH] Code cleanups from pyupgrade Found by running: ``` make pyupgrade ``` --- lib/galaxy/files/sources/__init__.py | 3 +-- lib/galaxy/files/sources/http.py | 3 +-- lib/galaxy/jobs/runners/kubernetes.py | 3 +-- lib/galaxy/managers/datasets.py | 3 +-- lib/galaxy/tools/parameters/dynamic_options.py | 3 +-- lib/galaxy/webapps/galaxy/api/__init__.py | 3 +-- lib/galaxy/webapps/galaxy/controllers/admin.py | 12 ++++-------- lib/galaxy/webapps/galaxy/controllers/forms.py | 3 +-- lib/galaxy_test/selenium/framework.py | 3 +-- test/unit/webapps/api/test_cbv.py | 3 +-- 10 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/galaxy/files/sources/__init__.py b/lib/galaxy/files/sources/__init__.py index 0339e3aaed48..61d6a328108e 100644 --- a/lib/galaxy/files/sources/__init__.py +++ b/lib/galaxy/files/sources/__init__.py @@ -468,8 +468,7 @@ def _get_error_msg_for(rule_name: str) -> str: def uri_join(*args): # url_join doesn't work with non-standard scheme - arg0 = args[0] - if "://" in arg0: + if "://" in (arg0 := args[0]): scheme, path = arg0.split("://", 1) rval = f"{scheme}://{slash_join(path, *args[1:]) if path else slash_join(*args[1:])}" else: diff --git a/lib/galaxy/files/sources/http.py b/lib/galaxy/files/sources/http.py index d2a5b331ccea..0e538baec1dc 100644 --- a/lib/galaxy/files/sources/http.py +++ b/lib/galaxy/files/sources/http.py @@ -85,8 +85,7 @@ def _serialization_props(self, user_context=None) -> HTTPFilesSourceProperties: return cast(HTTPFilesSourceProperties, effective_props) def score_url_match(self, url: str): - match = self._url_regex.match(url) - if match: + if match := self._url_regex.match(url): return match.span()[1] else: return 0 diff --git a/lib/galaxy/jobs/runners/kubernetes.py b/lib/galaxy/jobs/runners/kubernetes.py index e534c54e2239..a360f0c87aab 100644 --- a/lib/galaxy/jobs/runners/kubernetes.py +++ b/lib/galaxy/jobs/runners/kubernetes.py @@ -972,8 +972,7 @@ def __cleanup_k8s_guest_ports(self, job_wrapper, k8s_job): else: log.debug(f"No service found for job with k8s_job_name {k8s_job_name}") # remove the interactive environment entrypoints - eps = job_wrapper.get_job().interactivetool_entry_points - if eps: + if eps := job_wrapper.get_job().interactivetool_entry_points: log.debug(f"Removing entry points for job with ID {job_wrapper.get_id_tag()}") self.app.interactivetool_manager.remove_entry_points(eps) diff --git a/lib/galaxy/managers/datasets.py b/lib/galaxy/managers/datasets.py index 612a69989deb..207d92ca407c 100644 --- a/lib/galaxy/managers/datasets.py +++ b/lib/galaxy/managers/datasets.py @@ -164,8 +164,7 @@ def update_object_store_id(self, trans, dataset, object_store_id: str): # has been shared. raise exceptions.InsufficientPermissionsException("Cannot change dataset permissions...") - quota_source_map = self.app.object_store.get_quota_source_map() - if quota_source_map: + if quota_source_map := self.app.object_store.get_quota_source_map(): old_label = quota_source_map.get_quota_source_label(old_object_store_id) new_label = quota_source_map.get_quota_source_label(new_object_store_id) if old_label != new_label: diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py index c93665945d26..4423a9a1bfd6 100644 --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -912,8 +912,7 @@ def strip_or_none(maybe_string: Optional[Element]) -> Optional[str]: def parse_from_url_options(elem: Element) -> Optional[FromUrlOptions]: - from_url = elem.get("from_url") - if from_url: + if from_url := elem.get("from_url"): request_method = cast(Literal["GET", "POST"], elem.get("request_method", "GET")) assert request_method in get_args(REQUEST_METHODS) request_headers = strip_or_none(elem.find("request_headers")) diff --git a/lib/galaxy/webapps/galaxy/api/__init__.py b/lib/galaxy/webapps/galaxy/api/__init__.py index 66e12cc4fd9b..3f19076a2367 100644 --- a/lib/galaxy/webapps/galaxy/api/__init__.py +++ b/lib/galaxy/webapps/galaxy/api/__init__.py @@ -157,8 +157,7 @@ def get_api_user( ), ), ) -> Optional[User]: - api_key = key or x_api_key - if api_key: + if api_key := key or x_api_key: user = user_manager.by_api_key(api_key=api_key) elif bearer_token: user = user_manager.by_oidc_access_token(access_token=bearer_token.credentials) diff --git a/lib/galaxy/webapps/galaxy/controllers/admin.py b/lib/galaxy/webapps/galaxy/controllers/admin.py index 3990ba190d59..0070c9be7c56 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin.py @@ -125,8 +125,7 @@ def apply_query_filter(self, query, **kwargs): } deleted = False purged = False - search_query = kwargs.get("search") - if search_query: + if search_query := kwargs.get("search"): parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS) for term in parsed_search.terms: if isinstance(term, FilteredTerm): @@ -195,8 +194,7 @@ def apply_query_filter(self, query, **kwargs): } deleted = False query = query.filter(self.model_class.type != self.model_class.types.PRIVATE) - search_query = kwargs.get("search") - if search_query: + if search_query := kwargs.get("search"): parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS) for term in parsed_search.terms: if isinstance(term, FilteredTerm): @@ -255,8 +253,7 @@ def apply_query_filter(self, query, **kwargs): "is": "is", } deleted = False - search_query = kwargs.get("search") - if search_query: + if search_query := kwargs.get("search"): parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS) for term in parsed_search.terms: if isinstance(term, FilteredTerm): @@ -326,8 +323,7 @@ def apply_query_filter(self, query, **kwargs): "is": "is", } deleted = False - search_query = kwargs.get("search") - if search_query: + if search_query := kwargs.get("search"): parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS) for term in parsed_search.terms: if isinstance(term, FilteredTerm): diff --git a/lib/galaxy/webapps/galaxy/controllers/forms.py b/lib/galaxy/webapps/galaxy/controllers/forms.py index f62ef7c272cb..112f8fa998cc 100644 --- a/lib/galaxy/webapps/galaxy/controllers/forms.py +++ b/lib/galaxy/webapps/galaxy/controllers/forms.py @@ -69,8 +69,7 @@ def apply_query_filter(self, query, **kwargs): } deleted = False query = query.join(model.FormDefinition, self.model_class.latest_form_id == model.FormDefinition.id) - search_query = kwargs.get("search") - if search_query: + if search_query := kwargs.get("search"): parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS) for term in parsed_search.terms: if isinstance(term, FilteredTerm): diff --git a/lib/galaxy_test/selenium/framework.py b/lib/galaxy_test/selenium/framework.py index 5b919286dbc3..310c88c88053 100644 --- a/lib/galaxy_test/selenium/framework.py +++ b/lib/galaxy_test/selenium/framework.py @@ -587,8 +587,7 @@ def assert_item_hid_text(self, hid): class UsesWorkflowAssertions(NavigatesGalaxyMixin): @retry_assertion_during_transitions def _assert_showing_n_workflows(self, n): - actual_count = len(self.workflow_card_elements()) - if actual_count != n: + if (actual_count := len(self.workflow_card_elements())) != n: message = f"Expected {n} workflows to be displayed, based on DOM found {actual_count} workflow rows." raise AssertionError(message) diff --git a/test/unit/webapps/api/test_cbv.py b/test/unit/webapps/api/test_cbv.py index df3e9db3a5d0..4d12cf079763 100644 --- a/test/unit/webapps/api/test_cbv.py +++ b/test/unit/webapps/api/test_cbv.py @@ -8,7 +8,6 @@ from typing import ( Any, ClassVar, - Optional, ) from fastapi import ( @@ -85,7 +84,7 @@ class RootHandler: @router.get("/items/?") @router.get("/items/{item_path:path}") @router.get("/database/{item_path:path}") - def root(self, item_path: Optional[str] = None, item_query: Optional[str] = None) -> Any: # noqa: UP007 + def root(self, item_path: str | None = None, item_query: str | None = None) -> Any: if item_path: return {"item_path": item_path} if item_query: