For Python ≤ 3.8:
from typing import Union, Tuple, List
Is
Union[List[str], List[Tuple[str, str]]]
the same as
List[Union[str, Tuple[str, str]]]
CodePudding user response:
They are not logically the same. The first is either a list of strings or a list of tuples; the second is a list that can contain strings and tuples.
['alpha', ('beta', 'gamma')]
is valid as List[Union[str, Tuple[str, str]]]
, but not valid as Union[List[str], List[Tuple[str, str]]]
.