[Python] VS Code Intellisense's response for FastAPI's `response_model`

Discussão em 'Python' iniciado por Stack, Dezembro 2, 2024.

  1. Stack

    Stack Membro Participativo

    In the code below, Vs Code suggests that the output should be of type Any instead of UserOut. Did I miss out on some configurations on my 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


    [​IMG]

    Continue reading...

Compartilhe esta Página