Browse Source

fix: types, so the linter won't show an error about mismatching types

pull/14573/head
luffy977338 7 months ago
parent
commit
6b37eea69d
  1. 21
      docs_src/app_testing/app_b_an_py310/main.py
  2. 18
      docs_src/app_testing/app_b_an_py39/main.py
  3. 21
      docs_src/app_testing/app_b_py310/main.py
  4. 21
      docs_src/app_testing/app_b_py39/main.py

21
docs_src/app_testing/app_b_an_py310/main.py

@ -3,21 +3,22 @@ from typing import Annotated
from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel
fake_secret_token = "coneofsilence"
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
foo_item = Item(id="foo", title="Foo", description="There goes my hero")
bar_item = Item(id="bar", title="Bar", description="The bartenders")
fake_secret_token = "coneofsilence"
fake_db: dict[str, Item] = {
"foo": foo_item,
"bar": bar_item,
}
app = FastAPI()
@app.get("/items/{item_id}", response_model=Item)
async def read_main(item_id: str, x_token: Annotated[str, Header()]):

18
docs_src/app_testing/app_b_an_py39/main.py

@ -3,20 +3,24 @@ 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
foo_item = Item(id="foo", title="Foo", description="There goes my hero")
bar_item = Item(id="bar", title="Bar", description="The bartenders")
fake_secret_token = "coneofsilence"
fake_db = {
"foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},
"bar": {"id": "bar", "title": "Bar", "description": "The bartenders"},
fake_db: dict[str, Item] = {
"foo": foo_item,
"bar": bar_item,
}
app = FastAPI()
class Item(BaseModel):
id: str
title: str
description: Union[str, None] = None
@app.get("/items/{item_id}", response_model=Item)

21
docs_src/app_testing/app_b_py310/main.py

@ -1,21 +1,22 @@
from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel
fake_secret_token = "coneofsilence"
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
foo_item = Item(id="foo", title="Foo", description="There goes my hero")
bar_item = Item(id="bar", title="Bar", description="The bartenders")
fake_secret_token = "coneofsilence"
fake_db: dict[str, Item] = {
"foo": foo_item,
"bar": bar_item,
}
app = FastAPI()
@app.get("/items/{item_id}", response_model=Item)
async def read_main(item_id: str, x_token: str = Header()):

21
docs_src/app_testing/app_b_py39/main.py

@ -3,21 +3,22 @@ from typing import Union
from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel
fake_secret_token = "coneofsilence"
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
foo_item = Item(id="foo", title="Foo", description="There goes my hero")
bar_item = Item(id="bar", title="Bar", description="The bartenders")
fake_secret_token = "coneofsilence"
fake_db: dict[str, Item] = {
"foo": foo_item,
"bar": bar_item,
}
app = FastAPI()
@app.get("/items/{item_id}", response_model=Item)
async def read_main(item_id: str, x_token: str = Header()):

Loading…
Cancel
Save