I have a function that takes 3 arguments and returns an image, I want to know that is the python type hint that the function returns.

Here is my function:

from PIL import Image

def modify_image(img_path: str, width: int, height: int) -> "what here?":
    """Read and return a resized image"""
    image = Image.open(img_path)
    modified_image = image.resize((width, height))

    return modified_image

推荐答案

According to the Pillow documentation, both Image.open() and Image.resize return Pillow Image objects, so your function should look something like

from PIL import Image

def modify_image(img_path: str, width: int, height: int) -> Image:
    ...

Python相关问答推荐

如何在具有重复数据的pandas中对groupby进行总和,同时保留其他列

Python 约束无法解决n皇后之谜

不理解Value错误:在Python中使用迭代对象设置时必须具有相等的len键和值

将输入管道传输到正在运行的Python脚本中

无法在Docker内部运行Python的Matlab SDK模块,但本地没有问题

mypy无法推断类型参数.List和Iterable的区别

如何在FastAPI中为我上传的json文件提供索引ID?

如何使用Numpy. stracards重新编写滚动和?

从列表中获取n个元素,其中list [i][0]== value''

如何找出Pandas 图中的连续空值(NaN)?

OpenCV轮廓.很难找到给定图像的所需轮廓

在numpy数组中寻找楼梯状 struct

如何将相同组的值添加到嵌套的Pandas Maprame的倒数第二个索引级别

使用np.fft.fft2和cv2.dft重现相位谱.为什么结果并不相似呢?

来自Airflow Connection的额外参数

当我定义一个继承的类时,我可以避免使用`metaclass=`吗?

python3中np. divide(x,y)和x/y有什么区别?'

如何在不遇到IndexError的情况下将基数10的整数转换为基数80?

Pandas:根据相邻行之间的差异过滤数据帧

是否将列表分割为2?