How to use the union operator for typing instead of typing.Union
Since python 3.10 we can use the union operator | instead of typing.Union to define a union of types. In this example, we can write str | None to define a type that accepts str as well as NoneType. This is equivalent to writing typing.Union[str, None] or typing.Optional[str]. In general, we can define optional types with the union operator as T | None.
dependencies: python3.10
Comments
Post a Comment