在下面的代码中,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
我相信这是默认行为,除非我们使用不同的方法来键入提示返回类型,如教程中指定的那样。