From 80c11148d37d79eeb611fa999b8f5ce4dd771da3 Mon Sep 17 00:00:00 2001 From: luffy977338 Date: Tue, 6 Jan 2026 19:00:23 +0300 Subject: [PATCH] fix: use model_dump() to avoid pyright errors --- docs_src/app_testing/app_b_an_py310/main.py | 21 ++++++++++----------- docs_src/app_testing/app_b_an_py39/main.py | 21 ++++++++++----------- docs_src/app_testing/app_b_py310/main.py | 21 ++++++++++----------- docs_src/app_testing/app_b_py39/main.py | 21 ++++++++++----------- 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/docs_src/app_testing/app_b_an_py310/main.py b/docs_src/app_testing/app_b_an_py310/main.py index b1894d34d..af67298d2 100644 --- a/docs_src/app_testing/app_b_an_py310/main.py +++ b/docs_src/app_testing/app_b_an_py310/main.py @@ -3,23 +3,22 @@ from typing import Annotated from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel - -class Item(BaseModel): - id: str - title: str - description: str | None = None - - fake_secret_token = "coneofsilence" -fake_db: dict[str, Item] = { - "foo": Item(id="foo", title="Foo", description="There goes my hero"), - "bar": Item(id="bar", title="Bar", description="The bartenders"), +fake_db = { + "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"}, + "bar": {"id": "bar", "title": "Bar", "description": "The bartenders"}, } app = FastAPI() +class Item(BaseModel): + id: str + title: str + description: str | None = None + + @app.get("/items/{item_id}", response_model=Item) async def read_main(item_id: str, x_token: Annotated[str, Header()]): if x_token != fake_secret_token: @@ -35,5 +34,5 @@ async def create_item(item: Item, x_token: Annotated[str, Header()]): raise HTTPException(status_code=400, detail="Invalid X-Token header") if item.id in fake_db: raise HTTPException(status_code=409, detail="Item already exists") - fake_db[item.id] = item + fake_db[item.id] = item.model_dump() return item diff --git a/docs_src/app_testing/app_b_an_py39/main.py b/docs_src/app_testing/app_b_an_py39/main.py index e1ad7cccd..11e740777 100644 --- a/docs_src/app_testing/app_b_an_py39/main.py +++ b/docs_src/app_testing/app_b_an_py39/main.py @@ -3,23 +3,22 @@ from typing import Annotated, Union from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel - -class Item(BaseModel): - id: str - title: str - description: Union[str, None] = None - - fake_secret_token = "coneofsilence" -fake_db: dict[str, Item] = { - "foo": Item(id="foo", title="Foo", description="There goes my hero"), - "bar": Item(id="bar", title="Bar", description="The bartenders"), +fake_db = { + "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"}, + "bar": {"id": "bar", "title": "Bar", "description": "The bartenders"}, } app = FastAPI() +class Item(BaseModel): + id: str + title: str + description: Union[str, None] = None + + @app.get("/items/{item_id}", response_model=Item) async def read_main(item_id: str, x_token: Annotated[str, Header()]): if x_token != fake_secret_token: @@ -35,5 +34,5 @@ async def create_item(item: Item, x_token: Annotated[str, Header()]): raise HTTPException(status_code=400, detail="Invalid X-Token header") if item.id in fake_db: raise HTTPException(status_code=409, detail="Item already exists") - fake_db[item.id] = item + fake_db[item.id] = item.model_dump() return item diff --git a/docs_src/app_testing/app_b_py310/main.py b/docs_src/app_testing/app_b_py310/main.py index c41d31767..955acfbae 100644 --- a/docs_src/app_testing/app_b_py310/main.py +++ b/docs_src/app_testing/app_b_py310/main.py @@ -1,23 +1,22 @@ from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel - -class Item(BaseModel): - id: str - title: str - description: str | None = None - - fake_secret_token = "coneofsilence" -fake_db: dict[str, Item] = { - "foo": Item(id="foo", title="Foo", description="There goes my hero"), - "bar": Item(id="bar", title="Bar", description="The bartenders"), +fake_db = { + "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"}, + "bar": {"id": "bar", "title": "Bar", "description": "The bartenders"}, } app = FastAPI() +class Item(BaseModel): + id: str + title: str + description: str | None = None + + @app.get("/items/{item_id}", response_model=Item) async def read_main(item_id: str, x_token: str = Header()): if x_token != fake_secret_token: @@ -33,5 +32,5 @@ async def create_item(item: Item, x_token: str = Header()): raise HTTPException(status_code=400, detail="Invalid X-Token header") if item.id in fake_db: raise HTTPException(status_code=409, detail="Item already exists") - fake_db[item.id] = item + fake_db[item.id] = item.model_dump() return item diff --git a/docs_src/app_testing/app_b_py39/main.py b/docs_src/app_testing/app_b_py39/main.py index 18fe10251..4fd44dfd1 100644 --- a/docs_src/app_testing/app_b_py39/main.py +++ b/docs_src/app_testing/app_b_py39/main.py @@ -3,23 +3,22 @@ from typing import Union from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel - -class Item(BaseModel): - id: str - title: str - description: Union[str, None] = None - - fake_secret_token = "coneofsilence" -fake_db: dict[str, Item] = { - "foo": Item(id="foo", title="Foo", description="There goes my hero"), - "bar": Item(id="bar", title="Bar", description="The bartenders"), +fake_db = { + "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"}, + "bar": {"id": "bar", "title": "Bar", "description": "The bartenders"}, } app = FastAPI() +class Item(BaseModel): + id: str + title: str + description: Union[str, None] = None + + @app.get("/items/{item_id}", response_model=Item) async def read_main(item_id: str, x_token: str = Header()): if x_token != fake_secret_token: @@ -35,5 +34,5 @@ async def create_item(item: Item, x_token: str = Header()): raise HTTPException(status_code=400, detail="Invalid X-Token header") if item.id in fake_db: raise HTTPException(status_code=409, detail="Item already exists") - fake_db[item.id] = item + fake_db[item.id] = item.model_dump() return item