From ef2c58b6df7affb82c0b1668bdec643d57ec9c86 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Fri, 2 Sep 2022 16:45:05 +0100 Subject: [PATCH] Method parameters cleanup and type annotation --- lib/galaxy/tool_util/parser/output_actions.py | 26 +++++++++---------- .../tools/parameters/dynamic_options.py | 4 +-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/galaxy/tool_util/parser/output_actions.py b/lib/galaxy/tool_util/parser/output_actions.py index e190d50d43f..7efe258957a 100644 --- a/lib/galaxy/tool_util/parser/output_actions.py +++ b/lib/galaxy/tool_util/parser/output_actions.py @@ -31,7 +31,7 @@ class ToolOutputActionGroup: else: log.debug(f"Unknown ToolOutputAction tag specified: {elem.tag}") - def apply_action(self, output_dataset, other_values): + def apply_action(self, output_dataset, other_values) -> None: for action in self.actions: action.apply_action(output_dataset, other_values) @@ -62,26 +62,26 @@ class ToolOutputActionConditionalWhen(ToolOutputActionGroup): super().__init__(parent, config_elem) self.value = value - def is_case(self, output_dataset, other_values): + def is_case(self, other_values): raise TypeError("Not implemented") - def get_ref(self, output_dataset, other_values): + def get_ref(self, other_values): ref = other_values for ref_name in self.parent.name: assert ref_name in ref, f"Required dependency '{ref_name}' not found in incoming values" ref = ref.get(ref_name) return ref - def apply_action(self, output_dataset, other_values): - if self.is_case(output_dataset, other_values): - return super().apply_action(output_dataset, other_values) + def apply_action(self, output_dataset, other_values) -> None: + if self.is_case(other_values): + super().apply_action(output_dataset, other_values) class ValueToolOutputActionConditionalWhen(ToolOutputActionConditionalWhen): tag = "when value" - def is_case(self, output_dataset, other_values): - ref = self.get_ref(output_dataset, other_values) + def is_case(self, other_values) -> bool: + ref = self.get_ref(other_values) return ref == self.value @@ -92,8 +92,8 @@ class DatatypeIsInstanceToolOutputActionConditionalWhen(ToolOutputActionConditio super().__init__(parent, config_elem, value) self.value = type(self.tool.app.datatypes_registry.get_datatype_by_extension(value)) - def is_case(self, output_dataset, other_values): - ref = self.get_ref(output_dataset, other_values) + def is_case(self, other_values) -> bool: + ref = self.get_ref(other_values) return isinstance(ref.datatype, self.value) @@ -109,7 +109,7 @@ class ToolOutputActionConditional: for when_elem in config_elem.findall("when"): self.cases.append(ToolOutputActionConditionalWhen.from_elem(self, when_elem)) - def apply_action(self, output_dataset, other_values): + def apply_action(self, output_dataset, other_values) -> None: for case in self.cases: case.apply_action(output_dataset, other_values) @@ -303,7 +303,7 @@ class MetadataToolOutputAction(ToolOutputAction): self.name = elem.get("name", None) assert self.name is not None, "Required 'name' attribute missing from MetadataToolOutputAction" - def apply_action(self, output_dataset, other_values): + def apply_action(self, output_dataset, other_values) -> None: value = self.option.get_value(other_values) # TODO: figure out correct type based on MetadataElementSpec, # but MetadataElementSpec doesn't actually define a type (but it should). @@ -327,7 +327,7 @@ class FormatToolOutputAction(ToolOutputAction): super().__init__(parent, elem) self.default = elem.get("default", None) - def apply_action(self, output_dataset, other_values): + def apply_action(self, output_dataset, other_values) -> None: value = self.option.get_value(other_values) if value is None and self.default is not None: value = self.default diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py index 896ba8f1c14..14360f3c666 100644 --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -491,9 +491,7 @@ class RemoveValueFilter(Filter): data_ref = other_values.get(self.meta_ref) if isinstance(data_ref, HistoryDatasetCollectionAssociation): data_ref = data_ref.to_hda_representative() - if not isinstance(data_ref, HistoryDatasetAssociation) and not isinstance( - data_ref, DatasetFilenameWrapper - ): + if not isinstance(data_ref, (HistoryDatasetAssociation, DatasetFilenameWrapper)): return options # cannot modify options value = data_ref.metadata.get(self.metadata_key, None) # Default to the second column (i.e. 1) since this used to work only on options produced by the data_meta filter