是否可以创建一个类型,该类型是其中一项引用该类型的并集?
请参阅以下示例用例。这会失败,因为
Serialized
尚未声明。
from typing import List, Dict, Union
class MyClass:
# (...)
Serialized = Union[Dict[str, Serialized], List[Serialized], str, int, float, bool]
def serialize(self) -> Serialized:
...