Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/docs/python-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ You will see a lot more of all this in practice in the [Tutorial - User Guide](t

## Type Hints with Metadata Annotations

Python also has a feature that allows putting **additional metadata** in these type hints using `Annotated`.
Python also has a feature that allows putting **additional <abbr title="Data about the data, in this case, information about the type, e.g. a description.">metadata</abbr>** in these type hints using `Annotated`.

=== "Python 3.9+"

Expand Down
8 changes: 6 additions & 2 deletions docs/en/docs/tutorial/query-params-str-validations.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Now let's jump to the fun stuff. πŸŽ‰

## Add `Query` to `Annotated` in the `q` parameter

Now that we have this `Annotated` where we can put more metadata, add `Query` to it, and set the parameter `max_length` to 50:
Now that we have this `Annotated` where we can put more information (in this case some additional validation), add `Query` inside of `Annotated`, and set the parameter `max_length` to `50`:

=== "Python 3.10+"

Expand All @@ -115,7 +115,11 @@ Now that we have this `Annotated` where we can put more metadata, add `Query` to

Notice that the default value is still `None`, so the parameter is still optional.

But now, having `Query(max_length=50)` inside of `Annotated`, we are telling FastAPI that we want it to extract this value from the query parameters (this would have been the default anyway 🀷) and that we want to have **additional validation** for this value (that's why we do this, to get the additional validation). 😎
But now, having `Query(max_length=50)` inside of `Annotated`, we are telling FastAPI that we want it to have **additional validation** for this value, we want it to have maximum 50 characters. 😎

!!! tip

Here we are using `Query()` because this is a **query parameter**. Later we will see others like `Path()`, `Body()`, `Header()`, and `Cookie()`, that also accept the same arguments as `Query()`.

FastAPI will now:

Expand Down