Skip to content

Commit bb7e915

Browse files
mr-cnsoranzo
authored andcommitted
Fix type hints
1 parent 885aa22 commit bb7e915

File tree

8 files changed

+48
-26
lines changed

8 files changed

+48
-26
lines changed

lib/galaxy/datatypes/images.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,13 @@ def sniff_prefix(self, file_prefix):
305305
('header_size', 'i4'),
306306
]
307307
np_dtype = np.dtype(header_def)
308-
header = np.ndarray(
309-
shape=(),
310-
dtype=np_dtype,
311-
buffer=header_raw)
312-
if header['header_size'] == 1000 and b'TRACK' in header['magic'] and \
313-
header['version'] == 2 and len(header['dim']) == 3:
308+
header: np.ndarray = np.ndarray(shape=(), dtype=np_dtype, buffer=header_raw)
309+
if (
310+
header["header_size"] == 1000
311+
and b"TRACK" in header["magic"]
312+
and header["version"] == 2
313+
and len(header["dim"]) == 3
314+
):
314315
return True
315316
return False
316317

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
@@ -873,7 +873,7 @@ def get_inputs(self):
873873
cases = []
874874

875875
for param_type in ["text", "integer", "float", "boolean", "color", "field"]:
876-
default_source: Dict[str, Union[int, float, bool, str]] = dict(
876+
default_source: Dict[str, Union[None, int, float, bool, str]] = dict(
877877
name="default", label="Default Value", type=param_type
878878
)
879879
if param_type == "text":
@@ -885,6 +885,7 @@ def get_inputs(self):
885885
input_default_value: Union[
886886
TextToolParameter,
887887
IntegerToolParameter,
888+
FieldTypeToolParameter,
888889
FloatToolParameter,
889890
BooleanToolParameter,
890891
ColorToolParameter,
@@ -1722,7 +1723,7 @@ def decode_runtime_state(self, runtime_state):
17221723

17231724
def evaluate_value_from_expressions(self, progress, step, execution_state, extra_step_state):
17241725
value_from_expressions = {}
1725-
replacements = {}
1726+
replacements: Dict[str, str] = {}
17261727

17271728
for key in execution_state.inputs.keys():
17281729
step_input = step.inputs_by_name.get(key)
@@ -1876,8 +1877,17 @@ def callback(input, prefixed_name, **kwargs):
18761877
replacement = json.load(f)
18771878
found_replacement_keys.add(prefixed_name)
18781879

1879-
is_data = isinstance(input, DataToolParameter) or isinstance(input, DataCollectionToolParameter) or isinstance(input, FieldTypeToolParameter)
1880-
if not is_data and getattr(replacement, "history_content_type", None) == "dataset" and getattr(replacement, "ext", None) == "expression.json":
1880+
is_data = (
1881+
isinstance(input, DataToolParameter)
1882+
or isinstance(input, DataCollectionToolParameter)
1883+
or isinstance(input, FieldTypeToolParameter)
1884+
)
1885+
if (
1886+
not is_data
1887+
and not isinstance(replacement, NoReplacement)
1888+
and getattr(replacement, "history_content_type", None) == "dataset"
1889+
and getattr(replacement, "ext", None) == "expression.json"
1890+
):
18811891
if isinstance(replacement, model.HistoryDatasetAssociation):
18821892
if not replacement.dataset.in_ready_state():
18831893
why = "dataset [%s] is needed for non-data connection and is non-ready" % replacement.id
@@ -1891,11 +1901,11 @@ def callback(input, prefixed_name, **kwargs):
18911901

18921902
if isinstance(input, FieldTypeToolParameter):
18931903
if isinstance(replacement, model.HistoryDatasetAssociation):
1894-
replacement = {"src": "hda", "value": replacement}
1904+
return {"src": "hda", "value": replacement}
18951905
elif isinstance(replacement, model.HistoryDatasetCollectionAssociation):
1896-
replacement = {"src": "hdca", "value": replacement}
1906+
return {"src": "hdca", "value": replacement}
18971907
elif replacement is not NO_REPLACEMENT:
1898-
replacement = {"src": "json", "value": replacement}
1908+
return {"src": "json", "value": replacement}
18991909

19001910
return replacement
19011911

@@ -1938,9 +1948,9 @@ def expression_callback(input, prefixed_name, **kwargs):
19381948
if prefixed_name in expression_replacements:
19391949
expression_replacement = expression_replacements[prefixed_name]
19401950
if isinstance(input, FieldTypeToolParameter):
1941-
replacement = {"src": "json", "value": expression_replacement}
1951+
return {"src": "json", "value": expression_replacement}
19421952
else:
1943-
replacement = expression_replacement
1953+
return expression_replacement
19441954

19451955
return replacement
19461956

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")

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
@@ -472,7 +472,7 @@ def run_conformance_test(self, version, doc):
472472
directory = os.path.join(CWL_TOOL_DIRECTORY, version)
473473
tool = os.path.join(directory, test["tool"])
474474
job_path = test.get("job")
475-
job = None
475+
job: Optional[Dict[str, str]] = None
476476
if job_path is not None:
477477
job_path = os.path.join(directory, job_path)
478478
else:

test/unit/app/tools/test_cwl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import shutil
44
import tempfile
5+
from typing import Dict
56
from unittest import TestCase
67
from uuid import uuid4
78

@@ -546,12 +547,12 @@ def tearDown(self):
546547
def test_default_data_inputs(self):
547548
self._init_tool(tool_path=_cwl_tool_path("v1.0/v1.0/default_path.cwl"))
548549
hda = self._new_hda()
549-
errors = {}
550+
errors: Dict[str, str] = {}
550551
cwl_inputs = {
551552
"file1": {"src": "hda", "id": self.app.security.encode_id(hda.id)}
552553
}
553554
inputs = self.tool.inputs_from_dict({"inputs": cwl_inputs, "inputs_representation": "cwl"})
554-
populated_state = {}
555+
populated_state: Dict[str, str] = {}
555556
populate_state(self.trans, self.tool.inputs, inputs, populated_state, errors)
556557
wrapped_params = WrappedParameters(self.trans, self.tool, populated_state)
557558
input_json = to_cwl_job(self.tool, wrapped_params.params, self.test_directory)

0 commit comments

Comments
 (0)