Python 3.7 关于PEP 484 multiple type怎么解释呢?

Python 3.7 About PEP 484 multiple type how to explain it?

def read_image(file):
    image = imread(file)
    return image

在这种情况下,我接受的文件是路径或图像数组,我如何为文件添加注释?

def read_image(file: str|array):

这可能吗?

更新

现在可以了。

关注@iggy12345

from typing import Union
def read_image(file: Union[str, list]):
    .....

你需要做的是使用 union 这允许你指定一个参数有多种类型,例如

from typing import union

def read_image(file: union[str, list]):
  pass

有关使用联合的详细信息,请参阅here