对于多种可能的输入,什么是最好的类型提示方式?
例如:
def example(input1):
return input1
如果input1
是,例如,10个可能的类之一,使用Union
还是最好的,或者有更好的方法?
恒等函数的类型通常为:
from typing import TypeVar
T = TypeVar('T')
def identity(x:T) -> T:
return x