类型限制 union union讲道理就是用来允许返回两种值,一般是none。如下: from typing import Union,TypeVar T = TypeVar('T') def f(x: T) -> Union[str, None]: if x: return "x"