VS Code Intellisense 对 FastAPI 的 `response_model` 的响应

问题描述 投票:0回答:1

在下面的代码中,Vs Code 建议输出类型应为

Any
而不是
UserOut
。我是否错过了 VS Code 上的某些配置?

# based on https://fastapi.tiangolo.com/tutorial/response-model/
from fastapi import FastAPI
from pydantic import BaseModel,

class UserIn(BaseModel):
    username: str
    password: str
    email: EmailStr
    full_name: str|None = None

class UserOut(BaseModel):
    username: str
    email: EmailStr
    full_name: str | None = None

app = FastAPI()

@app.post("/user2", response_model=UserOut)
async def create_user2(user: UserIn) -> Any:
    return user

On hover

python visual-studio-code fastapi intellisense
1个回答
0
投票

我相信这是默认行为,除非我们使用不同的方法来键入提示返回类型,如教程中指定的那样。

© www.soinside.com 2019 - 2024. All rights reserved.