gpt4 book ai didi

python - Flake8 抛出 B008 fastapi 数据类型定义

转载 作者:行者123 更新时间:2023-12-03 08:03:05 33 4
gpt4 key购买 nike

我有以下代码,它通过 fastapi 处理 POST 请求。但是,flake8 不断抛出 B008 不要在参数默认值中执行函数调用。该调用仅在函数定义时执行一次错误。

@app.post("/predict", status_code=200)
def predict(
page_no: int = Form(...), dimensions: list = Form(...), image: UploadFile = File(...)
) -> Dict[str, int]:

有办法修复或解决这些警告吗?

最佳答案

一种解决方案是更新您的 flake8 配置(例如在 setup.cfg 文件中),以忽略此 Depends(...) 用法的规则,如下所示:

extend-immutable-calls = Depends, fastapi.Depends, fastapi.params.Depends

截至 2022 年 12 月,您必须手动列出名称,因为 flake8-bugbear 插件不知道实际类型(它是 AST 解析器),there is an open issue about it .

查看更多:

关于python - Flake8 抛出 B008 fastapi 数据类型定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73306462/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com