如何访问(并迭代)
typing.Literal
对于上下文来说,这是为了避免两次定义文字列表。
typing.get_args
MyLiteral = Literal["foo", "bar"] for literal_option in typing.get_args(MyLiteral): print(literal_option)