@@ -50,7 +50,6 @@ class UnionType:
50
50
TYPE_ANNOTATION_TYPES = (type , typing ._GenericAlias , UnionType ) # type: ignore[attr-defined]
51
51
52
52
53
-
54
53
def _generate_metadata (f : Callable ) -> LatchMetadata :
55
54
signature = inspect .signature (f )
56
55
metadata = LatchMetadata (f .__name__ , LatchAuthor ())
@@ -72,7 +71,7 @@ def _inject_metadata(f: Callable, metadata: LatchMetadata) -> None:
72
71
# so that when users call @workflow without any arguments or
73
72
# parentheses, the workflow still serializes as expected
74
73
def workflow (
75
- metadata : Union [LatchMetadata , Callable ]
74
+ metadata : Union [LatchMetadata , Callable ],
76
75
) -> Union [PythonFunctionWorkflow , Callable ]:
77
76
if isinstance (metadata , Callable ):
78
77
f = metadata
@@ -141,25 +140,22 @@ def decorator(f: Callable):
141
140
142
141
143
142
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.
147
144
"""
148
145
annotation = parameter .annotation
149
146
150
147
# If the parameter did not have a type annotation, short-circuit and return False
151
148
if not _is_type_annotation (annotation ):
152
149
return False
153
150
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 ))
157
154
)
158
155
159
156
160
157
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.
163
159
164
160
Args:
165
161
dtype: A type.
@@ -187,8 +183,7 @@ def _is_list_of_dataclasses_type(dtype: TypeAnnotation) -> bool:
187
183
188
184
189
185
def _is_optional_type (dtype : TypeAnnotation ) -> bool :
190
- """
191
- Check if a type is `Optional`.
186
+ """Check if a type is `Optional`.
192
187
193
188
An optional type may be declared using three syntaxes: `Optional[T]`, `Union[T, None]`, or `T |
194
189
None`. All of these syntaxes is supported by this function.
@@ -211,12 +206,15 @@ def _is_optional_type(dtype: TypeAnnotation) -> bool:
211
206
212
207
# Optional[T] has `typing.Union` as its origin, but PEP604 syntax (e.g. `int | None`) has
213
208
# `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
+ )
215
214
216
215
217
216
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`.
220
218
221
219
Args:
222
220
dtype: A type of `Optional[T]`, `T | None`, or `Union[T, None]`.
@@ -246,8 +244,7 @@ def _unpack_optional_type(dtype: TypeAnnotation) -> type:
246
244
247
245
248
246
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.
251
248
252
249
If the corresponding parameter **did not** have a type annotation, `annotation` is set to the
253
250
special class variable `Parameter.empty`.
0 commit comments