in google_cloud_automlops/orchestration/base.py [0:0]
def maybe_strip_optional_from_annotation(self, annotation: T) -> T:
"""Strips 'Optional' from 'Optional[<type>]' if applicable.
For example::
Optional[str] -> str
str -> str
List[int] -> List[int]
Args:
annotation: The original type annotation which may or may not has `Optional`.
Returns:
The type inside Optional[] if Optional exists, otherwise the original type.
"""
if getattr(annotation, '__origin__', None) is Union and annotation.__args__[1] is type(None):
return annotation.__args__[0]
else:
return annotation