TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' [duplicate]

发布时间 2023-10-01 10:48:37作者: DaisyLinux

 

 

str | None syntax is only supported in 3.10 or later. Use

from typing import Optional
name: Optional[str] = None
For cases where the right hand side isn't None or there are more than two types, you can use Union

from typing import Union
foo: Union[str, int, float] = "bar"