mirror of https://github.com/tiangolo/fastapi.git
Remove code examples for Python 3.8 in `path_params_numeric_validations`
This commit is contained in:
parent
f57bac4afb
commit
66de805333
|
|
@ -54,7 +54,7 @@ It doesn't matter for **FastAPI**. It will detect the parameters by their names,
|
|||
|
||||
So, you can declare your function as:
|
||||
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial002.py hl[7] *}
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial002_py39.py hl[7] *}
|
||||
|
||||
But keep in mind that if you use `Annotated`, you won't have this problem, it won't matter as you're not using the function parameter default values for `Query()` or `Path()`.
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ Pass `*`, as the first parameter of the function.
|
|||
|
||||
Python won't do anything with that `*`, but it will know that all the following parameters should be called as keyword arguments (key-value pairs), also known as <abbr title="From: K-ey W-ord Arg-uments"><code>kwargs</code></abbr>. Even if they don't have a default value.
|
||||
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial003.py hl[7] *}
|
||||
{* ../../docs_src/path_params_numeric_validations/tutorial003_py39.py hl[7] *}
|
||||
|
||||
### Better with `Annotated` { #better-with-annotated }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
from typing import Union
|
||||
|
||||
from fastapi import FastAPI, Path, Query
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get")],
|
||||
q: Annotated[Union[str, None], Query(alias="item-query")] = None,
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
from fastapi import FastAPI, Path
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
q: str, item_id: Annotated[int, Path(title="The ID of the item to get")]
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
from fastapi import FastAPI, Path
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get")], q: str
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
from fastapi import FastAPI, Path
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get", ge=1)], q: str
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
from fastapi import FastAPI, Path
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get", gt=0, le=1000)],
|
||||
q: str,
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
from fastapi import FastAPI, Path, Query
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(
|
||||
*,
|
||||
item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)],
|
||||
q: str,
|
||||
size: Annotated[float, Query(gt=0, lt=10.5)],
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
if size:
|
||||
results.update({"size": size})
|
||||
return results
|
||||
Loading…
Reference in New Issue