Before Python 3.10, you need to use typing.Union to declare that a variable can have one of several different types.
typing.Union
In Python 3.10, you can replace Union[X, Y] with X | Y to simplify the expression.
Union[X, Y]
X | Y
Simplify Nested Structures with Python Data Classes
Simplify Object Creation with Python Class Methods
Optimizing Memory Usage in Python with Slots