对于 Python ≤ 3.8:
from typing import Union, Tuple, List
是
Union[List[str], List[Tuple[str, str]]]
与
相同List[Union[str, Tuple[str, str]]]
它们在逻辑上并不相同。第一个是字符串列表或元组列表;第二个是可以包含字符串和元组的列表。
['alpha', ('beta', 'gamma')]
与 List[Union[str, Tuple[str, str]]]
有效,但与 Union[List[str], List[Tuple[str, str]]]
无效。