Skip to content

Commit e7869bf

Browse files
mr-cnsoranzo
authored andcommitted
Fix type hints
1 parent 40a0c6d commit e7869bf

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
lines changed

lib/galaxy/tools/wrappers.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Any,
88
cast,
99
Dict,
10+
ItemsView,
1011
Iterable,
1112
Iterator,
1213
KeysView,
@@ -56,7 +57,7 @@ class ToolParameterValueWrapper:
5657
Base class for object that Wraps a Tool Parameter and Value.
5758
"""
5859

59-
value: Union[str, List[str]]
60+
value: Union[None, str, List[str], Dict[str, str]]
6061
input: "ToolParameter"
6162

6263
def __bool__(self) -> bool:
@@ -103,10 +104,12 @@ class InputValueWrapper(ToolParameterValueWrapper):
103104
Wraps an input so that __str__ gives the "param_dict" representation.
104105
"""
105106

107+
value: Optional[Dict[str, str]]
108+
106109
def __init__(
107110
self,
108111
input: "ToolParameter",
109-
value: str,
112+
value: Dict[str, str],
110113
other_values: Optional[Dict[str, str]] = None,
111114
) -> None:
112115
self.input = input
@@ -172,6 +175,7 @@ class SelectToolParameterWrapper(ToolParameterValueWrapper):
172175
"""
173176

174177
input: "SelectToolParameter"
178+
value: Union[str, List[str]]
175179

176180
class SelectToolParameterFieldWrapper:
177181
"""
@@ -625,9 +629,13 @@ def __init__(
625629
self.collection = collection
626630

627631
elements = collection.elements
628-
element_instances = {}
632+
element_instances: Dict[
633+
str, Union[DatasetCollectionWrapper, DatasetFilenameWrapper]
634+
] = {}
629635

630-
element_instance_list = []
636+
element_instance_list: List[
637+
Union[DatasetCollectionWrapper, DatasetFilenameWrapper]
638+
] = []
631639
for dataset_collection_element in elements:
632640
element_object = dataset_collection_element.element_object
633641
element_identifier = dataset_collection_element.element_identifier
@@ -662,7 +670,9 @@ def keys(self) -> Union[List[str], KeysView[Any]]:
662670
return []
663671
return self.__element_instances.keys()
664672

665-
def items(self):
673+
def items(
674+
self,
675+
) -> ItemsView[str, Union["DatasetCollectionWrapper", DatasetFilenameWrapper]]:
666676
return self.__element_instances.items()
667677

668678
@property

lib/galaxy/workflow/modules.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def get_inputs(self):
879879
cases = []
880880

881881
for param_type in ["text", "integer", "float", "boolean", "color", "field"]:
882-
default_source: Dict[str, Union[int, float, bool, str]] = dict(
882+
default_source: Dict[str, Union[None, int, float, bool, str]] = dict(
883883
name="default", label="Default Value", type=param_type
884884
)
885885
if param_type == "text":
@@ -891,6 +891,7 @@ def get_inputs(self):
891891
input_default_value: Union[
892892
TextToolParameter,
893893
IntegerToolParameter,
894+
FieldTypeToolParameter,
894895
FloatToolParameter,
895896
BooleanToolParameter,
896897
ColorToolParameter,
@@ -1728,7 +1729,7 @@ def decode_runtime_state(self, runtime_state):
17281729

17291730
def evaluate_value_from_expressions(self, progress, step, execution_state, extra_step_state):
17301731
value_from_expressions = {}
1731-
replacements = {}
1732+
replacements: Dict[str, str] = {}
17321733

17331734
for key in execution_state.inputs.keys():
17341735
step_input = step.inputs_by_name.get(key)
@@ -1882,8 +1883,17 @@ def callback(input, prefixed_name, **kwargs):
18821883
replacement = json.load(f)
18831884
found_replacement_keys.add(prefixed_name)
18841885

1885-
is_data = isinstance(input, DataToolParameter) or isinstance(input, DataCollectionToolParameter) or isinstance(input, FieldTypeToolParameter)
1886-
if not is_data and getattr(replacement, "history_content_type", None) == "dataset" and getattr(replacement, "ext", None) == "expression.json":
1886+
is_data = (
1887+
isinstance(input, DataToolParameter)
1888+
or isinstance(input, DataCollectionToolParameter)
1889+
or isinstance(input, FieldTypeToolParameter)
1890+
)
1891+
if (
1892+
not is_data
1893+
and not isinstance(replacement, NoReplacement)
1894+
and getattr(replacement, "history_content_type", None) == "dataset"
1895+
and getattr(replacement, "ext", None) == "expression.json"
1896+
):
18871897
if isinstance(replacement, model.HistoryDatasetAssociation):
18881898
if not replacement.dataset.in_ready_state():
18891899
why = "dataset [%s] is needed for non-data connection and is non-ready" % replacement.id
@@ -1897,11 +1907,11 @@ def callback(input, prefixed_name, **kwargs):
18971907

18981908
if isinstance(input, FieldTypeToolParameter):
18991909
if isinstance(replacement, model.HistoryDatasetAssociation):
1900-
replacement = {"src": "hda", "value": replacement}
1910+
return {"src": "hda", "value": replacement}
19011911
elif isinstance(replacement, model.HistoryDatasetCollectionAssociation):
1902-
replacement = {"src": "hdca", "value": replacement}
1912+
return {"src": "hdca", "value": replacement}
19031913
elif replacement is not NO_REPLACEMENT:
1904-
replacement = {"src": "json", "value": replacement}
1914+
return {"src": "json", "value": replacement}
19051915

19061916
return replacement
19071917

@@ -1944,9 +1954,9 @@ def expression_callback(input, prefixed_name, **kwargs):
19441954
if prefixed_name in expression_replacements:
19451955
expression_replacement = expression_replacements[prefixed_name]
19461956
if isinstance(input, FieldTypeToolParameter):
1947-
replacement = {"src": "json", "value": expression_replacement}
1957+
return {"src": "json", "value": expression_replacement}
19481958
else:
1949-
replacement = expression_replacement
1959+
return expression_replacement
19501960

19511961
return replacement
19521962

lib/galaxy/workflow/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,10 @@ def replacement_for_input_connections(self, step, input_dict, connections):
367367
else:
368368
raise NotImplementedError()
369369

370-
ephemeral_collection = modules.EphemeralCollection(
370+
return modules.EphemeralCollection(
371371
collection=collection,
372372
history=self.workflow_invocation.history,
373373
)
374-
replacement = ephemeral_collection
375374

376375
return replacement
377376

lib/galaxy_test/api/test_tools_cwl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_any1_file(self):
327327
test_data_directory="test/functional/tools/cwl_tools/v1.0/v1.0/",
328328
)
329329
output1_content = self.dataset_populator.get_history_dataset_content(run_object.history_id)
330-
self.dataset_populator._summarize_history_errors(run_object.history_id)
330+
self.dataset_populator._summarize_history(run_object.history_id)
331331
assert output1_content == '"File"', "[%s]" % output1_content
332332

333333
@skip_without_tool("any1.cwl")

lib/galaxy_test/api/test_workflows_cwl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
class BaseCwlWorklfowTestCase(BaseWorkflowsApiTestCase):
14+
history_id: str
1415
allow_path_paste = True
1516
require_admin_user = True
1617

lib/galaxy_test/base/populators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def run_conformance_test(self, version, doc):
473473
directory = os.path.join(CWL_TOOL_DIRECTORY, version)
474474
tool = os.path.join(directory, test["tool"])
475475
job_path = test.get("job")
476-
job = None
476+
job: Optional[Dict[str, str]] = None
477477
if job_path is not None:
478478
job_path = os.path.join(directory, job_path)
479479
else:

0 commit comments

Comments
 (0)