in google_cloud_automlops/orchestration/base.py [0:0]
def _get_function_return_types(self) -> list:
"""Returns a formatted list of function return types.
Returns:
list: return value list with types converted to kubeflow spec.
Raises:
Exception: If return type is provided and not a NamedTuple.
"""
# Extract return type annotation of function
annotation = inspect.signature(self.func).return_annotation
# Ensures return type is not optional
if self.maybe_strip_optional_from_annotation(annotation) is not annotation:
raise TypeError('Return type cannot be Optional.')
# No annotations provided, return none
# pylint: disable=protected-access
if annotation == inspect._empty:
return None
# Checks if the function's return type annotation is a valid NamedTuple
if not (hasattr(annotation,'__annotations__') and isinstance(annotation.__annotations__, dict)):
raise TypeError(f'''Return type hint for function "{self.name}" must be a NamedTuple.''')
# Creates a dictionary of metadata for each object returned by component
outputs = []
for name, type_ in annotation.__annotations__.items():
metadata = {}
metadata['name'] = name
metadata['type'] = type_
metadata['description'] = None
outputs.append(metadata)
return outputs