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

Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,7 @@ The *path operation decorator* receives an optional argument `dependencies`.

It should be a `list` of `Depends()`:

//// tab | Python 3.9+

```Python hl_lines="19"
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="18"
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```

////

//// tab | Python 3.8 non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="17"
{!> ../../docs_src/dependencies/tutorial006.py!}
```

////
{* ../../docs_src/dependencies/tutorial006_an_py39.py hl[19] *}

These dependencies will be executed/solved the same way as normal dependencies. But their value (if they return any) won't be passed to your *path operation function*.

Expand Down Expand Up @@ -72,105 +44,21 @@ You can use the same dependency *functions* you use normally.

They can declare request requirements (like headers) or other sub-dependencies:

//// tab | Python 3.9+

```Python hl_lines="8 13"
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="7 12"
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```

////

//// tab | Python 3.8 non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="6 11"
{!> ../../docs_src/dependencies/tutorial006.py!}
```

////
{* ../../docs_src/dependencies/tutorial006_an_py39.py hl[8,13] *}

### Raise exceptions

These dependencies can `raise` exceptions, the same as normal dependencies:

//// tab | Python 3.9+

```Python hl_lines="10 15"
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="9 14"
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```

////

//// tab | Python 3.8 non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="8 13"
{!> ../../docs_src/dependencies/tutorial006.py!}
```

////
{* ../../docs_src/dependencies/tutorial006_an_py39.py hl[10,15] *}

### Return values

And they can return values or not, the values won't be used.

So, you can reuse a normal dependency (that returns a value) you already use somewhere else, and even though the value won't be used, the dependency will be executed:

//// tab | Python 3.9+

```Python hl_lines="11 16"
{!> ../../docs_src/dependencies/tutorial006_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="10 15"
{!> ../../docs_src/dependencies/tutorial006_an.py!}
```

////

//// tab | Python 3.8 non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="9 14"
{!> ../../docs_src/dependencies/tutorial006.py!}
```

////
{* ../../docs_src/dependencies/tutorial006_an_py39.py hl[11,16] *}

## Dependencies for a group of *path operations*

Expand Down