Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f60f342

Browse files
committedJul 19, 2024
refactor: extract _is_valid_samplesheet_parameter_type
1 parent ce51f8e commit f60f342

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed
 

‎latch/resources/workflow.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,7 @@ def decorator(f: Callable):
8181
if meta_param.samplesheet is not True:
8282
continue
8383

84-
annotation = wf_params[name].annotation
85-
86-
origin = get_origin(annotation)
87-
args = get_args(annotation)
88-
valid = (
89-
origin is not None
90-
and issubclass(origin, list)
91-
and is_dataclass(args[0])
92-
)
93-
if not valid:
84+
if not _is_valid_samplesheet_parameter_type(wf_param[name]):
9485
click.secho(
9586
f"parameter marked as samplesheet is not valid: {name} "
9687
f"in workflow {f.__name__} must be a list of dataclasses",
@@ -108,3 +99,21 @@ def decorator(f: Callable):
10899
return _workflow(f, wf_name_override=wf_name_override)
109100

110101
return decorator
102+
103+
104+
def _is_valid_samplesheet_parameter_type(parameter: inspect.Parameter) -> bool:
105+
"""
106+
Check if a parameter in the workflow function's signature is annotated with a valid type for a
107+
samplesheet LatchParameter.
108+
"""
109+
annotation = parameter.annotation
110+
111+
origin = get_origin(annotation)
112+
args = get_args(annotation)
113+
valid = (
114+
origin is not None
115+
and issubclass(origin, list)
116+
and is_dataclass(args[0])
117+
)
118+
119+
return valid

0 commit comments

Comments
 (0)
Please sign in to comment.