Skip to content

Commit

Permalink
⬆️ Update Pydantic to 0.21.0 (tiangolo#90)
Browse files Browse the repository at this point in the history
* ⬆️ Upgrade Pydantic and others (isort), update docs after changes by isort

* 🎨 Format with newest isort, update type hints in jsonable_encoder

* 🔧 Update test script, to avoid Pydantic type errors

* ⬆️ Update pyproject.toml with latest Pydantic
  • Loading branch information
tiangolo committed Mar 21, 2019
1 parent f2fd948 commit 108c2f3
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uvicorn = "*"

[packages]
starlette = "==0.11.1"
pydantic = "==0.18.2"
pydantic = "==0.21.0"

[requires]
python_version = "3.6"
Expand Down
102 changes: 50 additions & 52 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions docs/src/application_configuration/tutorial002.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from fastapi import FastAPI

app = FastAPI(
openapi_url="/api/v1/openapi.json"
)
app = FastAPI(openapi_url="/api/v1/openapi.json")


@app.get("/items/")
Expand Down
5 changes: 1 addition & 4 deletions docs/src/application_configuration/tutorial003.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from fastapi import FastAPI

app = FastAPI(
docs_url="/documentation",
redoc_url=None,
)
app = FastAPI(docs_url="/documentation", redoc_url=None)


@app.get("/items/")
Expand Down
3 changes: 1 addition & 2 deletions docs/src/bigger_applications/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from fastapi import FastAPI

from .routers import items
from .routers import users
from .routers import items, users

app = FastAPI()

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/application-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ But you can configure it with the parameter `openapi_url`.

For example, to set it to be served at `/api/v1/openapi.json`:

```Python hl_lines="4"
```Python hl_lines="3"
{!./src/application_configuration/tutorial002.py!}
```

Expand All @@ -46,6 +46,6 @@ You can configure the two documentation user interfaces included:

For example, to set Swagger UI to be served at `/documentation` and disable ReDoc:

```Python hl_lines="4 5"
```Python hl_lines="3"
{!./src/application_configuration/tutorial003.py!}
```
16 changes: 8 additions & 8 deletions docs/tutorial/bigger-applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ This will be the main file in your application that ties everything together.

You import and create a `FastAPI` class as normally:

```Python hl_lines="1 6"
```Python hl_lines="1 5"
{!./src/bigger_applications/app/main.py!}
```

Expand All @@ -129,7 +129,7 @@ But this time we are not adding *path operations* directly with the `FastAPI` `a

We import the other submodules that have `APIRouter`s:

```Python hl_lines="3 4"
```Python hl_lines="3"
{!./src/bigger_applications/app/main.py!}
```

Expand All @@ -141,21 +141,21 @@ As the file `app/routers/items.py` is part of the same Python package, we can im
The section:

```Python
from .routers import items
from .routers import items, users
```

Means:

* Starting in the same package that this module (the file `app/main.py`) lives in (the directory `app/`)...
* look for the subpackage `routers` (the directory at `app/routers/`)...
* and from it, import the submodule `items` (the file at `app/routers/items.py`)...
* and from it, import the submodule `items` (the file at `app/routers/items.py`) and `users` (the file at `app/routers/users.py`)...

The module `items` will have a variable `router` (`items.router`). This is the same one we created in the file `app/routers/items.py`. It's an `APIRouter`.
The module `items` will have a variable `router` (`items.router`). This is the same one we created in the file `app/routers/items.py`. It's an `APIRouter`. The same for the module `users`.

We could also import it like:
We could also import them like:

```Python
from app.routers import items
from app.routers import items, users
```

!!! info
Expand Down Expand Up @@ -183,7 +183,7 @@ The `router` from `users` would overwrite the one from `items` and we wouldn't b

So, to be able to use both of them in the same file, we import the submodules directly:

```Python hl_lines="3 4"
```Python hl_lines="3"
{!./src/bigger_applications/app/main.py!}
```

Expand Down
4 changes: 2 additions & 2 deletions fastapi/encoders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from types import GeneratorType
from typing import Any, Set
from typing import Any, List, Set

from pydantic import BaseModel
from pydantic.json import ENCODERS_BY_TYPE
Expand Down Expand Up @@ -70,7 +70,7 @@ def jsonable_encoder(
)
)
return encoded_list
errors = []
errors: List[Exception] = []
try:
if custom_encoder and type(obj) in custom_encoder:
encoder = custom_encoder[type(obj)]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
requires = [
"starlette ==0.11.1",
"pydantic >=0.17,<=0.18.2"
"pydantic >=0.17,<=0.21.0"
]
description-file = "README.md"
requires-python = ">=3.6"
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi

export PYTHONPATH=./docs/src
pytest --cov=fastapi --cov=tests --cov=docs/src --cov-report=term-missing ${@}
mypy fastapi --disallow-untyped-defs
mypy fastapi --disallow-untyped-defs --follow-imports=skip
if [ "${PYTHON_VERSION}" = '3.7' ]; then
echo "Skipping 'black' on 3.7. See issue https://github.com/ambv/black/issues/494"
else
Expand Down

0 comments on commit 108c2f3

Please sign in to comment.