Skip to content

Commit da486cb

Browse files
committed
chore: ruff
1 parent 939d3e1 commit da486cb

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

latch/resources/workflow.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class UnionType:
5050
TYPE_ANNOTATION_TYPES = (type, typing._GenericAlias, UnionType) # type: ignore[attr-defined]
5151

5252

53-
5453
def _generate_metadata(f: Callable) -> LatchMetadata:
5554
signature = inspect.signature(f)
5655
metadata = LatchMetadata(f.__name__, LatchAuthor())
@@ -72,7 +71,7 @@ def _inject_metadata(f: Callable, metadata: LatchMetadata) -> None:
7271
# so that when users call @workflow without any arguments or
7372
# parentheses, the workflow still serializes as expected
7473
def workflow(
75-
metadata: Union[LatchMetadata, Callable]
74+
metadata: Union[LatchMetadata, Callable],
7675
) -> Union[PythonFunctionWorkflow, Callable]:
7776
if isinstance(metadata, Callable):
7877
f = metadata
@@ -141,25 +140,22 @@ def decorator(f: Callable):
141140

142141

143142
def _is_valid_samplesheet_parameter_type(parameter: inspect.Parameter) -> bool:
144-
"""
145-
Check if a parameter in the workflow function's signature is annotated with a valid type for a
146-
samplesheet LatchParameter.
143+
"""Check if a workflow parameter is hinted with a valid type for a samplesheet LatchParameter.
147144
"""
148145
annotation = parameter.annotation
149146

150147
# If the parameter did not have a type annotation, short-circuit and return False
151148
if not _is_type_annotation(annotation):
152149
return False
153150

154-
return (
155-
_is_list_of_dataclasses_type(annotation)
156-
or (_is_optional_type(annotation) and _is_list_of_dataclasses_type(_unpack_optional_type(annotation)))
151+
return _is_list_of_dataclasses_type(annotation) or (
152+
_is_optional_type(annotation)
153+
and _is_list_of_dataclasses_type(_unpack_optional_type(annotation))
157154
)
158155

159156

160157
def _is_list_of_dataclasses_type(dtype: TypeAnnotation) -> bool:
161-
"""
162-
Check if the type is a list of dataclasses.
158+
"""Check if the type is a list of dataclasses.
163159
164160
Args:
165161
dtype: A type.
@@ -187,8 +183,7 @@ def _is_list_of_dataclasses_type(dtype: TypeAnnotation) -> bool:
187183

188184

189185
def _is_optional_type(dtype: TypeAnnotation) -> bool:
190-
"""
191-
Check if a type is `Optional`.
186+
"""Check if a type is `Optional`.
192187
193188
An optional type may be declared using three syntaxes: `Optional[T]`, `Union[T, None]`, or `T |
194189
None`. All of these syntaxes is supported by this function.
@@ -211,12 +206,15 @@ def _is_optional_type(dtype: TypeAnnotation) -> bool:
211206

212207
# Optional[T] has `typing.Union` as its origin, but PEP604 syntax (e.g. `int | None`) has
213208
# `types.UnionType` as its origin.
214-
return (origin is Union or origin is UnionType) and len(args) == 2 and type(None) in args
209+
return (
210+
(origin is Union or origin is UnionType)
211+
and len(args) == 2
212+
and type(None) in args
213+
)
215214

216215

217216
def _unpack_optional_type(dtype: TypeAnnotation) -> type:
218-
"""
219-
Given a type of `Optional[T]`, return `T`.
217+
"""Given a type of `Optional[T]`, return `T`.
220218
221219
Args:
222220
dtype: A type of `Optional[T]`, `T | None`, or `Union[T, None]`.
@@ -246,8 +244,7 @@ def _unpack_optional_type(dtype: TypeAnnotation) -> type:
246244

247245

248246
def _is_type_annotation(annotation: Any) -> TypeGuard[TypeAnnotation]:
249-
"""
250-
Check if the annotation on an `inspect.Parameter` instance is a type annotation.
247+
"""Check if the annotation on an `inspect.Parameter` instance is a type annotation.
251248
252249
If the corresponding parameter **did not** have a type annotation, `annotation` is set to the
253250
special class variable `Parameter.empty`.

0 commit comments

Comments
 (0)