Skip to content

Commit e40ac19

Browse files
committed
doc: add docs
1 parent da486cb commit e40ac19

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

latch/resources/workflow.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ def decorator(f: Callable):
141141

142142
def _is_valid_samplesheet_parameter_type(parameter: inspect.Parameter) -> bool:
143143
"""Check if a workflow parameter is hinted with a valid type for a samplesheet LatchParameter.
144+
145+
Currently, a samplesheet LatchParameter must be defined as a list of dataclasses, or as an
146+
`Optional` list of dataclasses when the parameter is part of a `ForkBranch`.
147+
148+
Args:
149+
parameter: A parameter from the workflow function's signature.
150+
151+
Returns:
152+
True if the parameter is annotated as a list of dataclasses, or as an `Optional` list of
153+
dataclasses.
154+
False otherwise.
144155
"""
145156
annotation = parameter.annotation
146157

@@ -165,7 +176,7 @@ def _is_list_of_dataclasses_type(dtype: TypeAnnotation) -> bool:
165176
False otherwise.
166177
167178
Raises:
168-
TypeError: If the input is not a `type`.
179+
TypeError: If the input is not a valid `TypeAnnotation` type (see above).
169180
"""
170181
if not isinstance(dtype, TYPE_ANNOTATION_TYPES):
171182
raise TypeError(f"Expected `type`, got {type(dtype)}: {dtype}")
@@ -196,7 +207,7 @@ def _is_optional_type(dtype: TypeAnnotation) -> bool:
196207
False otherwise.
197208
198209
Raises:
199-
TypeError: If the input is not a `type`.
210+
TypeError: If the input is not a valid `TypeAnnotation` type (see above).
200211
"""
201212
if not isinstance(dtype, TYPE_ANNOTATION_TYPES):
202213
raise TypeError(f"Expected `type`, got {type(dtype)}: {dtype}")
@@ -223,7 +234,7 @@ def _unpack_optional_type(dtype: TypeAnnotation) -> type:
223234
The type `T`.
224235
225236
Raises:
226-
TypeError: If the input is not a `type`.
237+
TypeError: If the input is not a valid `TypeAnnotation` type (see above).
227238
ValueError: If the input type is not `Optional[T]`.
228239
"""
229240
if not isinstance(dtype, TYPE_ANNOTATION_TYPES):
@@ -243,25 +254,27 @@ def _unpack_optional_type(dtype: TypeAnnotation) -> type:
243254
return base_type
244255

245256

257+
# NB: `inspect.Parameter.annotation` is typed as `Any`, so here we narrow the type.
246258
def _is_type_annotation(annotation: Any) -> TypeGuard[TypeAnnotation]:
247259
"""Check if the annotation on an `inspect.Parameter` instance is a type annotation.
248260
249261
If the corresponding parameter **did not** have a type annotation, `annotation` is set to the
250-
special class variable `Parameter.empty`.
251-
252-
NB: `Parameter.empty` itself is a subclass of `type`
253-
Otherwise, the annotation is assumed to be a type.
262+
special class variable `inspect.Parameter.empty`. Otherwise, the annotation should be a valid
263+
type annotation.
254264
255265
Args:
256266
annotation: The annotation on an `inspect.Parameter` instance.
257267
258268
Returns:
259-
True if the annotation is not `Parameter.empty`.
269+
True if the type annotation is not `inspect.Parameter.empty`.
260270
False otherwise.
261271
262272
Raises:
263-
TypeError: If the annotation is neither a type nor `Parameter.empty`.
273+
TypeError: If the annotation is neither a valid `TypeAnnotation` type (see above) nor
274+
`inspect.Parameter.empty`.
264275
"""
276+
# NB: `inspect.Parameter.empty` is a subclass of `type`, so this check passes for unannotated
277+
# parameters.
265278
if not isinstance(annotation, TYPE_ANNOTATION_TYPES):
266279
raise TypeError(f"Annotation must be a type, not {type(annotation).__name__}")
267280

0 commit comments

Comments
 (0)