Skip to main content

get_optional_arg

Get the argument from an Optional[...] annotation, or None if it is no such annotation.

def get_optional_arg(
annotation: typing.Any
) - > typing.Any

Get the argument from an Optional[...] annotation, or None if it is no such annotation.

Parameters

NameTypeDescription
annotationtyping.AnyThe type hint annotation to inspect for an Optional or two-member Union containing None

Returns

TypeDescription
typing.AnyThe inner type argument of the Optional annotation if valid, otherwise None