Browse Source

⬆️ Update Pydantic to 0.21.0 (#90)

* ⬆️ 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
pull/91/head
Sebastián Ramírez 6 years ago
committed by GitHub
parent
commit
108c2f3c0e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Pipfile
  2. 102
      Pipfile.lock
  3. 4
      docs/src/application_configuration/tutorial002.py
  4. 5
      docs/src/application_configuration/tutorial003.py
  5. 3
      docs/src/bigger_applications/app/main.py
  6. 4
      docs/tutorial/application-configuration.md
  7. 16
      docs/tutorial/bigger-applications.md
  8. 4
      fastapi/encoders.py
  9. 2
      pyproject.toml
  10. 2
      scripts/test.sh

2
Pipfile

@ -26,7 +26,7 @@ uvicorn = "*"
[packages] [packages]
starlette = "==0.11.1" starlette = "==0.11.1"
pydantic = "==0.18.2" pydantic = "==0.21.0"
[requires] [requires]
python_version = "3.6" python_version = "3.6"

102
Pipfile.lock

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "f1f1b7fb88822fcf89e5073263c5a42234fa68d18ce0b1b82e4dd926bcdf12e9" "sha256": "676c6ae13691eef64abe6638f833cb8a330612521d3fad08718b240328b4877a"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -26,11 +26,11 @@
}, },
"pydantic": { "pydantic": {
"hashes": [ "hashes": [
"sha256:9f023811b6cefd203c5fd8fd15a4152f04e79e531b8f676ab1244dfe06ce8024", "sha256:93fa585402e7c8c01623ea8af6ca23363e8b4c6a020b7a2de9e99fa29d642d50",
"sha256:edbb08b561feda505374c0f25e4b54466a0a0c702ed6b2efaabdc3890d1a82e7" "sha256:eb441dd50779347a450494c437db3ecbb13c1f3854497df879662782af516c5c"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.18.2" "version": "==0.21.0"
}, },
"starlette": { "starlette": {
"hashes": [ "hashes": [
@ -86,11 +86,11 @@
}, },
"black": { "black": {
"hashes": [ "hashes": [
"sha256:817243426042db1d36617910df579a54f1afd659adb96fc5032fcf4b36209739", "sha256:09a9dcb7c46ed496a9850b76e4e825d6049ecd38b611f1224857a79bd985a8cf",
"sha256:e030a9a28f542debc08acceb273f228ac422798e5215ba2a791a6ddeaaca22a5" "sha256:68950ffd4d9169716bcb8719a56c07a2f4485354fec061cdd5910aa07369731c"
], ],
"index": "pypi", "index": "pypi",
"version": "==18.9b0" "version": "==19.3b0"
}, },
"bleach": { "bleach": {
"hashes": [ "hashes": [
@ -101,10 +101,10 @@
}, },
"certifi": { "certifi": {
"hashes": [ "hashes": [
"sha256:47f9c83ef4c0c621eaef743f133f09fa8a74a9b75f037e8624f83bd1b6626cb7", "sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
"sha256:993f830721089fef441cdfeb4b2c8c9df86f0c63239f06bd025a76a7daddb033" "sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae"
], ],
"version": "==2018.11.29" "version": "==2019.3.9"
}, },
"chardet": { "chardet": {
"hashes": [ "hashes": [
@ -156,10 +156,10 @@
}, },
"decorator": { "decorator": {
"hashes": [ "hashes": [
"sha256:33cd704aea07b4c28b3eb2c97d288a06918275dac0ecebdaf1bc8a48d98adb9e", "sha256:86156361c50488b84a3f148056ea716ca587df2f0de1d34750d35c21312725de",
"sha256:cabb249f4710888a2fc0e13e9a16c343d932033718ff62e1e9bc93a9d3a9122b" "sha256:f069f3a01830ca754ba5258fde2278454a0b5b79e0d7f5c13b3b97e57d4acff6"
], ],
"version": "==4.3.2" "version": "==4.4.0"
}, },
"defusedxml": { "defusedxml": {
"hashes": [ "hashes": [
@ -224,7 +224,6 @@
"hashes": [ "hashes": [
"sha256:e00cbd7ba01ff748e494248183abc6e153f49181169d8a3d41bb49132ca01dfc" "sha256:e00cbd7ba01ff748e494248183abc6e153f49181169d8a3d41bb49132ca01dfc"
], ],
"markers": "sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'pypy'",
"version": "==0.0.13" "version": "==0.0.13"
}, },
"idna": { "idna": {
@ -265,11 +264,11 @@
}, },
"isort": { "isort": {
"hashes": [ "hashes": [
"sha256:38a74a5ccf3a15a7a99f975071164f48d4d10eed4154879009c18e6e8933e5aa", "sha256:18c796c2cd35eb1a1d3f012a214a542790a1aed95e29768bdcb9f2197eccbd0b",
"sha256:abbb2684aa234d5eb8a67ef36d4aa62ea080d46c2eba36ad09e2990ae52e4305" "sha256:96151fca2c6e736503981896495d344781b60d18bfda78dc11b290c6125ebdb6"
], ],
"index": "pypi", "index": "pypi",
"version": "==4.3.13" "version": "==4.3.15"
}, },
"jedi": { "jedi": {
"hashes": [ "hashes": [
@ -445,10 +444,10 @@
}, },
"notebook": { "notebook": {
"hashes": [ "hashes": [
"sha256:9ca7f597ce4f5a24611c589fa320a7af2861f0ca1dc20839129c91ae354453fe", "sha256:18a98858c0331fb65a60f2ebb6439f8c0c4defd14ca363731b6cabc7f61624b4",
"sha256:c5011449a1a6d9f96bf65c4c2d6713802a21125476312b39c99010ccd7a2e2ed" "sha256:cc027a62be0f7756e0ef3d2d98458c4d7f4b3566449fb1a05891207f5bd9a1bf"
], ],
"version": "==5.7.5" "version": "==5.7.6"
}, },
"pandocfilters": { "pandocfilters": {
"hashes": [ "hashes": [
@ -550,11 +549,11 @@
}, },
"pytest": { "pytest": {
"hashes": [ "hashes": [
"sha256:067a1d4bf827ffdd56ad21bd46674703fce77c5957f6c1eef731f6146bfcef1c", "sha256:592eaa2c33fae68c7d75aacf042efc9f77b27c08a6224a4f59beab8d9a420523",
"sha256:9687049d53695ad45cf5fdc7bbd51f0c49f1ea3ecfc4b7f3fde7501b541f17f4" "sha256:ad3ad5c450284819ecde191a654c09b0ec72257a2c711b9633d677c71c9850c4"
], ],
"index": "pypi", "index": "pypi",
"version": "==4.3.0" "version": "==4.3.1"
}, },
"pytest-cov": { "pytest-cov": {
"hashes": [ "hashes": [
@ -586,19 +585,19 @@
}, },
"pyyaml": { "pyyaml": {
"hashes": [ "hashes": [
"sha256:544a0050e76e9b60751c58617fa28c253ad5d23af2e5f0b1c250390bf90bb0df", "sha256:1adecc22f88d38052fb787d959f003811ca858b799590a5eaa70e63dca50308c",
"sha256:594bf80477a58b6fd53e8b3f24ccf965c25eeeb6e05e4b1fb18c82c2d2090603", "sha256:436bc774ecf7c103814098159fbb84c2715d25980175292c648f2da143909f95",
"sha256:75e20ca689d0a2bf0c84f0e2028cc68ebef34b213fa66d73c410c53f870c49f4", "sha256:460a5a4248763f6f37ea225d19d5c205677d8d525f6a83357ca622ed541830c2",
"sha256:994da68a1dc1050f290f8017f044172360b608c0f2562b47645ecc69d7a61c0a", "sha256:5a22a9c84653debfbf198d02fe592c176ea548cccce47553f35f466e15cf2fd4",
"sha256:ad902e00088c50bdced94a57b819c24fdadaeaed5494df7a9a67d63774f210fd", "sha256:7a5d3f26b89d688db27822343dfa25c599627bc92093e788956372285c6298ad",
"sha256:b11aff75875ffc73541c4e4b1ac2f5e21717c1fc4396238943b9a44d962e74e1", "sha256:9372b04a02080752d9e6f990179a4ab840227c6e2ce15b95e1278456664cf2ba",
"sha256:bc733b5a9047c3e4848c0e80eeacfa6a799139242606410260c5450d665ea58c", "sha256:a5dcbebee834eaddf3fa7366316b880ff4062e4bcc9787b78c7fbb4a26ff2dd1",
"sha256:d960c68931b96bb215f385baa8ef867b8ebac66af60fa06cc1008f963848c7ad", "sha256:aee5bab92a176e7cd034e57f46e9df9a9862a71f8f37cad167c6fc74c65f5b4e",
"sha256:dd461c04e6a91e4eef7d5b75c1fc1c7013d3f8d354033b16526baadddd524079", "sha256:c51f642898c0bacd335fc119da60baae0824f2cde95b0330b56c0553439f0673",
"sha256:e4d6b5d6218a06f3141189d75c93876dd525a6d15f1b00ef4f274726c93719f1", "sha256:c68ea4d3ba1705da1e0d85da6684ac657912679a649e8868bd850d2c299cce13",
"sha256:f3c386fa12415bde8a0162745c4badf98fe171c6dfd67e54831f05ec88feeebb" "sha256:e23d0cc5299223dcc37885dae624f382297717e459ea24053709675a976a3e19"
], ],
"version": "==5.1b5" "version": "==5.1"
}, },
"pyzmq": { "pyzmq": {
"hashes": [ "hashes": [
@ -661,10 +660,10 @@
}, },
"sqlalchemy": { "sqlalchemy": {
"hashes": [ "hashes": [
"sha256:11ead7047ff3f394ed0d4b62aded6c5d970a9b718e1dc6add9f5e79442cc5b14" "sha256:781fb7b9d194ed3fc596b8f0dd4623ff160e3e825dd8c15472376a438c19598b"
], ],
"index": "pypi", "index": "pypi",
"version": "==1.3.0" "version": "==1.3.1"
}, },
"terminado": { "terminado": {
"hashes": [ "hashes": [
@ -746,26 +745,25 @@
}, },
"uvicorn": { "uvicorn": {
"hashes": [ "hashes": [
"sha256:8d523d0a003a874245025295b0c1233a762402c0d4c3988017401c6b461c83e9" "sha256:d700b65169820fc260f39402b7f966c178691daaa40cb376cad99d7cd737f772"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.5.1" "version": "==0.7.0b1"
}, },
"uvloop": { "uvloop": {
"hashes": [ "hashes": [
"sha256:198fe0c196056930ec6c4a0a878e531a66d15467ca7c74a875aa90271f0c6e3f", "sha256:0fcd894f6fc3226a962ee7ad895c4f52e3f5c3c55098e21efb17c071849a0573",
"sha256:1c175f47d34b84e33c0e312f4987c927ea004afc3a5f05d2f0f610d71d0e4c89", "sha256:2f31de1742c059c96cb76b91c5275b22b22b965c886ee1fced093fa27dde9e64",
"sha256:1c47f197be8f0a3c651dd20be1e1bd43268186246f246d4e86c91e95a89e4865", "sha256:459e4649fcd5ff719523de33964aa284898e55df62761e7773d088823ccbd3e0",
"sha256:3fd4943570d20e8cd4d9f0a3190ebd5cf040e5610b685e05c878128a11f7ad14", "sha256:67867aafd6e0bc2c30a079603a85d83b94f23c5593b3cc08ec7e58ac18bf48e5",
"sha256:435e232869923fd2248e4ca0ad73e24a5b4debf40bed9dcde133cfe1bef98a7a", "sha256:8c200457e6847f28d8bb91c5e5039d301716f5f2fce25646f5fb3fd65eda4a26",
"sha256:9cfdb966ae804c46b96c92207dfd2174935ffc70e706e42e1c94c60d16dbe860", "sha256:958906b9ca39eb158414fbb7d6b8ef1b7aee4db5c8e8e5d00fcbb69a1ce9dca7",
"sha256:a585781443eeb2edb858f8c08c503aac237a5f1bebf0c84ea8340cc337afa408", "sha256:ac1dca3d8f3ef52806059e81042ee397ac939e5a86c8a3cea55d6b087db66115",
"sha256:b296493e033846e46488a6aa227a75c790091f5ee5456ec637bb0badad1e8851", "sha256:b284c22d8938866318e3b9d178142b8be316c52d16fcfe1560685a686718a021",
"sha256:c684047c6cf6d697ba37872fb1b4489012ea91f3f802c8fbb9c367c4902e88dc", "sha256:c48692bf4587ce281d641087658eca275a5ad3b63c78297bbded96570ae9ce8f",
"sha256:da5a59d8812188b57b5783c7fb78891d14dd1050b6259680e0dbd4253d7d0f64" "sha256:fefc3b2b947c99737c348887db2c32e539160dcbeb7af9aa6b53db7a283538fe"
], ],
"markers": "sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'pypy'", "version": "==0.12.2"
"version": "==0.12.1"
}, },
"wcwidth": { "wcwidth": {
"hashes": [ "hashes": [

4
docs/src/application_configuration/tutorial002.py

@ -1,8 +1,6 @@
from fastapi import FastAPI from fastapi import FastAPI
app = FastAPI( app = FastAPI(openapi_url="/api/v1/openapi.json")
openapi_url="/api/v1/openapi.json"
)
@app.get("/items/") @app.get("/items/")

5
docs/src/application_configuration/tutorial003.py

@ -1,9 +1,6 @@
from fastapi import FastAPI from fastapi import FastAPI
app = FastAPI( app = FastAPI(docs_url="/documentation", redoc_url=None)
docs_url="/documentation",
redoc_url=None,
)
@app.get("/items/") @app.get("/items/")

3
docs/src/bigger_applications/app/main.py

@ -1,7 +1,6 @@
from fastapi import FastAPI from fastapi import FastAPI
from .routers import items from .routers import items, users
from .routers import users
app = FastAPI() app = FastAPI()

4
docs/tutorial/application-configuration.md

@ -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`: 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!} {!./src/application_configuration/tutorial002.py!}
``` ```
@ -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: 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!} {!./src/application_configuration/tutorial003.py!}
``` ```

16
docs/tutorial/bigger-applications.md

@ -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: 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!} {!./src/bigger_applications/app/main.py!}
``` ```
@ -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: We import the other submodules that have `APIRouter`s:
```Python hl_lines="3 4" ```Python hl_lines="3"
{!./src/bigger_applications/app/main.py!} {!./src/bigger_applications/app/main.py!}
``` ```
@ -141,21 +141,21 @@ As the file `app/routers/items.py` is part of the same Python package, we can im
The section: The section:
```Python ```Python
from .routers import items from .routers import items, users
``` ```
Means: Means:
* Starting in the same package that this module (the file `app/main.py`) lives in (the directory `app/`)... * 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/`)... * 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 ```Python
from app.routers import items from app.routers import items, users
``` ```
!!! info !!! info
@ -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: 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!} {!./src/bigger_applications/app/main.py!}
``` ```

4
fastapi/encoders.py

@ -1,6 +1,6 @@
from enum import Enum from enum import Enum
from types import GeneratorType from types import GeneratorType
from typing import Any, Set from typing import Any, List, Set
from pydantic import BaseModel from pydantic import BaseModel
from pydantic.json import ENCODERS_BY_TYPE from pydantic.json import ENCODERS_BY_TYPE
@ -70,7 +70,7 @@ def jsonable_encoder(
) )
) )
return encoded_list return encoded_list
errors = [] errors: List[Exception] = []
try: try:
if custom_encoder and type(obj) in custom_encoder: if custom_encoder and type(obj) in custom_encoder:
encoder = custom_encoder[type(obj)] encoder = custom_encoder[type(obj)]

2
pyproject.toml

@ -20,7 +20,7 @@ classifiers = [
] ]
requires = [ requires = [
"starlette ==0.11.1", "starlette ==0.11.1",
"pydantic >=0.17,<=0.18.2" "pydantic >=0.17,<=0.21.0"
] ]
description-file = "README.md" description-file = "README.md"
requires-python = ">=3.6" requires-python = ">=3.6"

2
scripts/test.sh

@ -13,7 +13,7 @@ fi
export PYTHONPATH=./docs/src export PYTHONPATH=./docs/src
pytest --cov=fastapi --cov=tests --cov=docs/src --cov-report=term-missing ${@} 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 if [ "${PYTHON_VERSION}" = '3.7' ]; then
echo "Skipping 'black' on 3.7. See issue https://github.com/ambv/black/issues/494" echo "Skipping 'black' on 3.7. See issue https://github.com/ambv/black/issues/494"
else else

Loading…
Cancel
Save