Since the documentation only uses Optional with a single type (Optional[X]), I was wondering if Union is required if I have an argument that accepts either a string, a list, or None.
def func(
arg: Optional[str, list]
)
def func(
arg: Optional[Union[str, list]]
)
>Solution :
Since Optional[...] is shorthand for Union[..., None], they are essentially the same, and you can just use Optional[str, list], since that’s the same as Union[str, list, None].