Browse Source

Remove code examples for Python 3.8 in `response_model`

pull/14510/head
Yurii Motov 7 months ago
parent
commit
3438b3e90e
  1. 4
      docs/en/docs/tutorial/response-model.md
  2. 27
      docs_src/response_model/tutorial001.py
  3. 27
      docs_src/response_model/tutorial001_01.py
  4. 0
      docs_src/response_model/tutorial002_py39.py
  5. 0
      docs_src/response_model/tutorial003_01_py39.py
  6. 0
      docs_src/response_model/tutorial003_02_py39.py
  7. 0
      docs_src/response_model/tutorial003_03_py39.py
  8. 0
      docs_src/response_model/tutorial003_04_py39.py
  9. 0
      docs_src/response_model/tutorial003_05_py39.py
  10. 0
      docs_src/response_model/tutorial003_py39.py
  11. 26
      docs_src/response_model/tutorial004.py
  12. 0
      docs_src/response_model/tutorial005_py39.py
  13. 0
      docs_src/response_model/tutorial006_py39.py
  14. 2
      tests/test_tutorial/test_response_model/test_tutorial003.py
  15. 2
      tests/test_tutorial/test_response_model/test_tutorial003_01.py
  16. 2
      tests/test_tutorial/test_response_model/test_tutorial003_02.py
  17. 2
      tests/test_tutorial/test_response_model/test_tutorial003_03.py
  18. 2
      tests/test_tutorial/test_response_model/test_tutorial003_04.py
  19. 2
      tests/test_tutorial/test_response_model/test_tutorial003_05.py
  20. 5
      tests/test_tutorial/test_response_model/test_tutorial004.py
  21. 2
      tests/test_tutorial/test_response_model/test_tutorial005.py
  22. 2
      tests/test_tutorial/test_response_model/test_tutorial006.py

4
docs/en/docs/tutorial/response-model.md

@ -183,7 +183,7 @@ There might be cases where you return something that is not a valid Pydantic fie
The most common case would be [returning a Response directly as explained later in the advanced docs](../advanced/response-directly.md){.internal-link target=_blank}.
{* ../../docs_src/response_model/tutorial003_02.py hl[8,10:11] *}
{* ../../docs_src/response_model/tutorial003_02_py39.py hl[8,10:11] *}
This simple case is handled automatically by FastAPI because the return type annotation is the class (or a subclass of) `Response`.
@ -193,7 +193,7 @@ And tools will also be happy because both `RedirectResponse` and `JSONResponse`
You can also use a subclass of `Response` in the type annotation:
{* ../../docs_src/response_model/tutorial003_03.py hl[8:9] *}
{* ../../docs_src/response_model/tutorial003_03_py39.py hl[8:9] *}
This will also work because `RedirectResponse` is a subclass of `Response`, and FastAPI will automatically handle this simple case.

27
docs_src/response_model/tutorial001.py

@ -1,27 +0,0 @@
from typing import Any, List, Union
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: Union[str, None] = None
price: float
tax: Union[float, None] = None
tags: List[str] = []
@app.post("/items/", response_model=Item)
async def create_item(item: Item) -> Any:
return item
@app.get("/items/", response_model=List[Item])
async def read_items() -> Any:
return [
{"name": "Portal Gun", "price": 42.0},
{"name": "Plumbus", "price": 32.0},
]

27
docs_src/response_model/tutorial001_01.py

@ -1,27 +0,0 @@
from typing import List, Union
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: Union[str, None] = None
price: float
tax: Union[float, None] = None
tags: List[str] = []
@app.post("/items/")
async def create_item(item: Item) -> Item:
return item
@app.get("/items/")
async def read_items() -> List[Item]:
return [
Item(name="Portal Gun", price=42.0),
Item(name="Plumbus", price=32.0),
]

0
docs_src/response_model/tutorial002.py → docs_src/response_model/tutorial002_py39.py

0
docs_src/response_model/tutorial003_01.py → docs_src/response_model/tutorial003_01_py39.py

0
docs_src/response_model/tutorial003_02.py → docs_src/response_model/tutorial003_02_py39.py

0
docs_src/response_model/tutorial003_03.py → docs_src/response_model/tutorial003_03_py39.py

0
docs_src/response_model/tutorial003_04.py → docs_src/response_model/tutorial003_04_py39.py

0
docs_src/response_model/tutorial003_05.py → docs_src/response_model/tutorial003_05_py39.py

0
docs_src/response_model/tutorial003.py → docs_src/response_model/tutorial003_py39.py

26
docs_src/response_model/tutorial004.py

@ -1,26 +0,0 @@
from typing import List, Union
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: Union[str, None] = None
price: float
tax: float = 10.5
tags: List[str] = []
items = {
"foo": {"name": "Foo", "price": 50.2},
"bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
"baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []},
}
@app.get("/items/{item_id}", response_model=Item, response_model_exclude_unset=True)
async def read_item(item_id: str):
return items[item_id]

0
docs_src/response_model/tutorial005.py → docs_src/response_model/tutorial005_py39.py

0
docs_src/response_model/tutorial006.py → docs_src/response_model/tutorial006_py39.py

2
tests/test_tutorial/test_response_model/test_tutorial003.py

@ -10,7 +10,7 @@ from ...utils import needs_py310
@pytest.fixture(
name="client",
params=[
"tutorial003",
pytest.param("tutorial003_py39"),
pytest.param("tutorial003_py310", marks=needs_py310),
],
)

2
tests/test_tutorial/test_response_model/test_tutorial003_01.py

@ -10,7 +10,7 @@ from ...utils import needs_py310
@pytest.fixture(
name="client",
params=[
"tutorial003_01",
pytest.param("tutorial003_01_py39"),
pytest.param("tutorial003_01_py310", marks=needs_py310),
],
)

2
tests/test_tutorial/test_response_model/test_tutorial003_02.py

@ -1,6 +1,6 @@
from fastapi.testclient import TestClient
from docs_src.response_model.tutorial003_02 import app
from docs_src.response_model.tutorial003_02_py39 import app
client = TestClient(app)

2
tests/test_tutorial/test_response_model/test_tutorial003_03.py

@ -1,6 +1,6 @@
from fastapi.testclient import TestClient
from docs_src.response_model.tutorial003_03 import app
from docs_src.response_model.tutorial003_03_py39 import app
client = TestClient(app)

2
tests/test_tutorial/test_response_model/test_tutorial003_04.py

@ -9,7 +9,7 @@ from ...utils import needs_py310
@pytest.mark.parametrize(
"module_name",
[
"tutorial003_04",
pytest.param("tutorial003_04_py39"),
pytest.param("tutorial003_04_py310", marks=needs_py310),
],
)

2
tests/test_tutorial/test_response_model/test_tutorial003_05.py

@ -9,7 +9,7 @@ from ...utils import needs_py310
@pytest.fixture(
name="client",
params=[
"tutorial003_05",
pytest.param("tutorial003_05_py39"),
pytest.param("tutorial003_05_py310", marks=needs_py310),
],
)

5
tests/test_tutorial/test_response_model/test_tutorial004.py

@ -4,14 +4,13 @@ import pytest
from dirty_equals import IsDict, IsOneOf
from fastapi.testclient import TestClient
from ...utils import needs_py39, needs_py310
from ...utils import needs_py310
@pytest.fixture(
name="client",
params=[
"tutorial004",
pytest.param("tutorial004_py39", marks=needs_py39),
pytest.param("tutorial004_py39"),
pytest.param("tutorial004_py310", marks=needs_py310),
],
)

2
tests/test_tutorial/test_response_model/test_tutorial005.py

@ -10,7 +10,7 @@ from ...utils import needs_py310
@pytest.fixture(
name="client",
params=[
"tutorial005",
pytest.param("tutorial005_py39"),
pytest.param("tutorial005_py310", marks=needs_py310),
],
)

2
tests/test_tutorial/test_response_model/test_tutorial006.py

@ -10,7 +10,7 @@ from ...utils import needs_py310
@pytest.fixture(
name="client",
params=[
"tutorial006",
pytest.param("tutorial006_py39"),
pytest.param("tutorial006_py310", marks=needs_py310),
],
)

Loading…
Cancel
Save