From 7da9625505386bae646c09a21b8b02a826e42119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 18 Dec 2018 22:36:04 +0400 Subject: [PATCH] :green_heart: Revert to flit install and re-format As it has shown to be more reliable, and closer to final user environments --- .travis.yml | 4 ++-- docs/tutorial/src/body/tutorial001.py | 3 +-- docs/tutorial/src/body/tutorial002.py | 3 +-- docs/tutorial/src/body/tutorial003.py | 3 +-- docs/tutorial/src/body/tutorial004.py | 3 +-- .../src/body_multiple_params/tutorial001.py | 3 +-- .../src/body_multiple_params/tutorial002.py | 3 +-- .../src/body_multiple_params/tutorial003.py | 3 +-- .../src/body_multiple_params/tutorial004.py | 3 +-- .../src/body_multiple_params/tutorial005.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial001.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial002.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial003.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial004.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial005.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial006.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial007.py | 3 +-- docs/tutorial/src/body_nested_models/tutorial008.py | 3 +-- docs/tutorial/src/body_schema/tutorial001.py | 3 +-- docs/tutorial/src/body_schema/tutorial002.py | 3 +-- docs/tutorial/src/custom_response/tutorial001.py | 3 +-- docs/tutorial/src/custom_response/tutorial002.py | 3 +-- docs/tutorial/src/custom_response/tutorial003.py | 3 +-- docs/tutorial/src/custom_response/tutorial004.py | 3 +-- docs/tutorial/src/dependencies/tutorial002.py | 3 +-- docs/tutorial/src/dependencies/tutorial003.py | 3 +-- docs/tutorial/src/dependencies/tutorial004.py | 3 +-- docs/tutorial/src/extra_models/tutorial001.py | 3 +-- docs/tutorial/src/extra_models/tutorial002.py | 3 +-- docs/tutorial/src/nosql_databases/tutorial001.py | 2 +- .../src/path_operation_configuration/tutorial001.py | 3 +-- .../src/path_operation_configuration/tutorial002.py | 3 +-- .../src/path_operation_configuration/tutorial003.py | 3 +-- .../src/path_operation_configuration/tutorial004.py | 3 +-- .../src/path_operation_configuration/tutorial005.py | 3 +-- docs/tutorial/src/response_model/tutorial001.py | 3 +-- docs/tutorial/src/response_model/tutorial002.py | 3 +-- docs/tutorial/src/response_model/tutorial003.py | 3 +-- docs/tutorial/src/security/tutorial002.py | 3 +-- docs/tutorial/src/security/tutorial003.py | 5 ++--- docs/tutorial/src/security/tutorial004.py | 5 ++--- docs/tutorial/src/sql_databases/tutorial001.py | 1 + fastapi/applications.py | 7 +++---- fastapi/dependencies/models.py | 3 +-- fastapi/dependencies/utils.py | 9 ++++----- fastapi/openapi/utils.py | 13 ++++++------- fastapi/routing.py | 9 ++++----- fastapi/security/api_key.py | 3 +-- fastapi/security/http.py | 3 +-- fastapi/security/oauth2.py | 5 ++--- fastapi/security/open_id_connect_url.py | 3 +-- fastapi/utils.py | 5 ++--- scripts/test.sh | 10 +++++----- tests/main_old.py | 7 +++---- 54 files changed, 78 insertions(+), 127 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b0260c01..a6dc5a675 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,8 @@ python: - "3.7-dev" install: - - pip install pipenv - - pipenv install --dev + - pip install flit + - flit install script: - bash scripts/test.sh diff --git a/docs/tutorial/src/body/tutorial001.py b/docs/tutorial/src/body/tutorial001.py index b3ccb12dd..e99a46ccc 100644 --- a/docs/tutorial/src/body/tutorial001.py +++ b/docs/tutorial/src/body/tutorial001.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel class Item(BaseModel): diff --git a/docs/tutorial/src/body/tutorial002.py b/docs/tutorial/src/body/tutorial002.py index 4b7412f42..cce5eca49 100644 --- a/docs/tutorial/src/body/tutorial002.py +++ b/docs/tutorial/src/body/tutorial002.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel class Item(BaseModel): diff --git a/docs/tutorial/src/body/tutorial003.py b/docs/tutorial/src/body/tutorial003.py index 312de2daf..1d3e90240 100644 --- a/docs/tutorial/src/body/tutorial003.py +++ b/docs/tutorial/src/body/tutorial003.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel class Item(BaseModel): diff --git a/docs/tutorial/src/body/tutorial004.py b/docs/tutorial/src/body/tutorial004.py index 499d5690d..c389af241 100644 --- a/docs/tutorial/src/body/tutorial004.py +++ b/docs/tutorial/src/body/tutorial004.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel class Item(BaseModel): diff --git a/docs/tutorial/src/body_multiple_params/tutorial001.py b/docs/tutorial/src/body_multiple_params/tutorial001.py index 4c1286ab3..fbd368207 100644 --- a/docs/tutorial/src/body_multiple_params/tutorial001.py +++ b/docs/tutorial/src/body_multiple_params/tutorial001.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI, Path +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_multiple_params/tutorial002.py b/docs/tutorial/src/body_multiple_params/tutorial002.py index 1db8d6e19..5c9e8344d 100644 --- a/docs/tutorial/src/body_multiple_params/tutorial002.py +++ b/docs/tutorial/src/body_multiple_params/tutorial002.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_multiple_params/tutorial003.py b/docs/tutorial/src/body_multiple_params/tutorial003.py index fa385d9cd..301f1a862 100644 --- a/docs/tutorial/src/body_multiple_params/tutorial003.py +++ b/docs/tutorial/src/body_multiple_params/tutorial003.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import Body, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_multiple_params/tutorial004.py b/docs/tutorial/src/body_multiple_params/tutorial004.py index 8ac1b4801..359b33ccc 100644 --- a/docs/tutorial/src/body_multiple_params/tutorial004.py +++ b/docs/tutorial/src/body_multiple_params/tutorial004.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import Body, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_multiple_params/tutorial005.py b/docs/tutorial/src/body_multiple_params/tutorial005.py index 2ff02e8c0..61f1b2917 100644 --- a/docs/tutorial/src/body_multiple_params/tutorial005.py +++ b/docs/tutorial/src/body_multiple_params/tutorial005.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import Body, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial001.py b/docs/tutorial/src/body_nested_models/tutorial001.py index 80dffebc4..9e0fa4494 100644 --- a/docs/tutorial/src/body_nested_models/tutorial001.py +++ b/docs/tutorial/src/body_nested_models/tutorial001.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial002.py b/docs/tutorial/src/body_nested_models/tutorial002.py index fba2b55e5..8f769279b 100644 --- a/docs/tutorial/src/body_nested_models/tutorial002.py +++ b/docs/tutorial/src/body_nested_models/tutorial002.py @@ -1,8 +1,7 @@ from typing import List -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial003.py b/docs/tutorial/src/body_nested_models/tutorial003.py index 412b5446d..bb539b127 100644 --- a/docs/tutorial/src/body_nested_models/tutorial003.py +++ b/docs/tutorial/src/body_nested_models/tutorial003.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial004.py b/docs/tutorial/src/body_nested_models/tutorial004.py index 5973cc2c2..257928ef3 100644 --- a/docs/tutorial/src/body_nested_models/tutorial004.py +++ b/docs/tutorial/src/body_nested_models/tutorial004.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial005.py b/docs/tutorial/src/body_nested_models/tutorial005.py index dca4c9816..f5f19b390 100644 --- a/docs/tutorial/src/body_nested_models/tutorial005.py +++ b/docs/tutorial/src/body_nested_models/tutorial005.py @@ -1,10 +1,9 @@ from typing import Set +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial006.py b/docs/tutorial/src/body_nested_models/tutorial006.py index 96071c319..09d8be768 100644 --- a/docs/tutorial/src/body_nested_models/tutorial006.py +++ b/docs/tutorial/src/body_nested_models/tutorial006.py @@ -1,10 +1,9 @@ from typing import List, Set +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial007.py b/docs/tutorial/src/body_nested_models/tutorial007.py index d3f915f0c..cda802d3e 100644 --- a/docs/tutorial/src/body_nested_models/tutorial007.py +++ b/docs/tutorial/src/body_nested_models/tutorial007.py @@ -1,10 +1,9 @@ from typing import List, Set +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/body_nested_models/tutorial008.py b/docs/tutorial/src/body_nested_models/tutorial008.py index 0f6a6e0ba..34b868563 100644 --- a/docs/tutorial/src/body_nested_models/tutorial008.py +++ b/docs/tutorial/src/body_nested_models/tutorial008.py @@ -1,10 +1,9 @@ from typing import List +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/body_schema/tutorial001.py b/docs/tutorial/src/body_schema/tutorial001.py index de9e82be7..6c8b101ba 100644 --- a/docs/tutorial/src/body_schema/tutorial001.py +++ b/docs/tutorial/src/body_schema/tutorial001.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel, Schema - from fastapi import Body, FastAPI +from pydantic import BaseModel, Schema app = FastAPI() diff --git a/docs/tutorial/src/body_schema/tutorial002.py b/docs/tutorial/src/body_schema/tutorial002.py index 3f83fb380..1165fd7a0 100644 --- a/docs/tutorial/src/body_schema/tutorial002.py +++ b/docs/tutorial/src/body_schema/tutorial002.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import Body, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/custom_response/tutorial001.py b/docs/tutorial/src/custom_response/tutorial001.py index 1e4b0491f..bba3f342d 100644 --- a/docs/tutorial/src/custom_response/tutorial001.py +++ b/docs/tutorial/src/custom_response/tutorial001.py @@ -1,6 +1,5 @@ -from starlette.responses import UJSONResponse - from fastapi import FastAPI +from starlette.responses import UJSONResponse app = FastAPI() diff --git a/docs/tutorial/src/custom_response/tutorial002.py b/docs/tutorial/src/custom_response/tutorial002.py index a9294d96e..214e64263 100644 --- a/docs/tutorial/src/custom_response/tutorial002.py +++ b/docs/tutorial/src/custom_response/tutorial002.py @@ -1,6 +1,5 @@ -from starlette.responses import HTMLResponse - from fastapi import FastAPI +from starlette.responses import HTMLResponse app = FastAPI() diff --git a/docs/tutorial/src/custom_response/tutorial003.py b/docs/tutorial/src/custom_response/tutorial003.py index 0186d15e9..ba0819cec 100644 --- a/docs/tutorial/src/custom_response/tutorial003.py +++ b/docs/tutorial/src/custom_response/tutorial003.py @@ -1,6 +1,5 @@ -from starlette.responses import HTMLResponse - from fastapi import FastAPI +from starlette.responses import HTMLResponse app = FastAPI() diff --git a/docs/tutorial/src/custom_response/tutorial004.py b/docs/tutorial/src/custom_response/tutorial004.py index ace5b900c..b19783c05 100644 --- a/docs/tutorial/src/custom_response/tutorial004.py +++ b/docs/tutorial/src/custom_response/tutorial004.py @@ -1,6 +1,5 @@ -from starlette.responses import HTMLResponse - from fastapi import FastAPI +from starlette.responses import HTMLResponse app = FastAPI() diff --git a/docs/tutorial/src/dependencies/tutorial002.py b/docs/tutorial/src/dependencies/tutorial002.py index 8870a646d..82a51634e 100644 --- a/docs/tutorial/src/dependencies/tutorial002.py +++ b/docs/tutorial/src/dependencies/tutorial002.py @@ -1,6 +1,5 @@ -from pydantic import BaseModel - from fastapi import Depends, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/dependencies/tutorial003.py b/docs/tutorial/src/dependencies/tutorial003.py index 412445b3c..e015f9585 100644 --- a/docs/tutorial/src/dependencies/tutorial003.py +++ b/docs/tutorial/src/dependencies/tutorial003.py @@ -1,8 +1,7 @@ from typing import List -from pydantic import BaseModel - from fastapi import Cookie, Depends, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/dependencies/tutorial004.py b/docs/tutorial/src/dependencies/tutorial004.py index 7d3fb54a7..3697b170a 100644 --- a/docs/tutorial/src/dependencies/tutorial004.py +++ b/docs/tutorial/src/dependencies/tutorial004.py @@ -1,9 +1,8 @@ from random import choice from typing import List -from pydantic import BaseModel - from fastapi import Cookie, Depends, FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/extra_models/tutorial001.py b/docs/tutorial/src/extra_models/tutorial001.py index 2fbea7d0d..aa8e7dad4 100644 --- a/docs/tutorial/src/extra_models/tutorial001.py +++ b/docs/tutorial/src/extra_models/tutorial001.py @@ -1,8 +1,7 @@ +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/extra_models/tutorial002.py b/docs/tutorial/src/extra_models/tutorial002.py index 68d9e2c63..605baf91f 100644 --- a/docs/tutorial/src/extra_models/tutorial002.py +++ b/docs/tutorial/src/extra_models/tutorial002.py @@ -1,8 +1,7 @@ +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/nosql_databases/tutorial001.py b/docs/tutorial/src/nosql_databases/tutorial001.py index ccb0cacf6..3a1d3fb52 100644 --- a/docs/tutorial/src/nosql_databases/tutorial001.py +++ b/docs/tutorial/src/nosql_databases/tutorial001.py @@ -1,11 +1,11 @@ from typing import Optional +from fastapi import FastAPI from pydantic import BaseModel from couchbase import LOCKMODE_WAIT from couchbase.bucket import Bucket from couchbase.cluster import Cluster, PasswordAuthenticator -from fastapi import FastAPI USERPROFILE_DOC_TYPE = "userprofile" diff --git a/docs/tutorial/src/path_operation_configuration/tutorial001.py b/docs/tutorial/src/path_operation_configuration/tutorial001.py index 39142fb62..b48601867 100644 --- a/docs/tutorial/src/path_operation_configuration/tutorial001.py +++ b/docs/tutorial/src/path_operation_configuration/tutorial001.py @@ -1,10 +1,9 @@ from typing import Set +from fastapi import FastAPI from pydantic import BaseModel from starlette.status import HTTP_201_CREATED -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/path_operation_configuration/tutorial002.py b/docs/tutorial/src/path_operation_configuration/tutorial002.py index d0a31c2d2..b5d0f12ca 100644 --- a/docs/tutorial/src/path_operation_configuration/tutorial002.py +++ b/docs/tutorial/src/path_operation_configuration/tutorial002.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/path_operation_configuration/tutorial003.py b/docs/tutorial/src/path_operation_configuration/tutorial003.py index 36217b039..106607fd2 100644 --- a/docs/tutorial/src/path_operation_configuration/tutorial003.py +++ b/docs/tutorial/src/path_operation_configuration/tutorial003.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/path_operation_configuration/tutorial004.py b/docs/tutorial/src/path_operation_configuration/tutorial004.py index d08a7722d..a4151a8cd 100644 --- a/docs/tutorial/src/path_operation_configuration/tutorial004.py +++ b/docs/tutorial/src/path_operation_configuration/tutorial004.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/path_operation_configuration/tutorial005.py b/docs/tutorial/src/path_operation_configuration/tutorial005.py index a563bd81e..f710e6c66 100644 --- a/docs/tutorial/src/path_operation_configuration/tutorial005.py +++ b/docs/tutorial/src/path_operation_configuration/tutorial005.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/response_model/tutorial001.py b/docs/tutorial/src/response_model/tutorial001.py index 19792ad84..86dadcbda 100644 --- a/docs/tutorial/src/response_model/tutorial001.py +++ b/docs/tutorial/src/response_model/tutorial001.py @@ -1,8 +1,7 @@ from typing import Set -from pydantic import BaseModel - from fastapi import FastAPI +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/response_model/tutorial002.py b/docs/tutorial/src/response_model/tutorial002.py index 5fdf7c97b..3fb475b9d 100644 --- a/docs/tutorial/src/response_model/tutorial002.py +++ b/docs/tutorial/src/response_model/tutorial002.py @@ -1,8 +1,7 @@ +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/response_model/tutorial003.py b/docs/tutorial/src/response_model/tutorial003.py index 745f07839..c8ea361d8 100644 --- a/docs/tutorial/src/response_model/tutorial003.py +++ b/docs/tutorial/src/response_model/tutorial003.py @@ -1,8 +1,7 @@ +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from fastapi import FastAPI - app = FastAPI() diff --git a/docs/tutorial/src/security/tutorial002.py b/docs/tutorial/src/security/tutorial002.py index 5b8de3e14..cfce06159 100644 --- a/docs/tutorial/src/security/tutorial002.py +++ b/docs/tutorial/src/security/tutorial002.py @@ -1,9 +1,8 @@ from typing import Optional -from pydantic import BaseModel - from fastapi import Depends, FastAPI, Security from fastapi.security import OAuth2PasswordBearer +from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/security/tutorial003.py b/docs/tutorial/src/security/tutorial003.py index 17f278193..4f3d2b82d 100644 --- a/docs/tutorial/src/security/tutorial003.py +++ b/docs/tutorial/src/security/tutorial003.py @@ -1,10 +1,9 @@ from typing import Optional -from pydantic import BaseModel -from starlette.exceptions import HTTPException - from fastapi import Depends, FastAPI, Security from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm +from pydantic import BaseModel +from starlette.exceptions import HTTPException fake_users_db = { "johndoe": { diff --git a/docs/tutorial/src/security/tutorial004.py b/docs/tutorial/src/security/tutorial004.py index 31ef7461b..122d4a101 100644 --- a/docs/tutorial/src/security/tutorial004.py +++ b/docs/tutorial/src/security/tutorial004.py @@ -2,15 +2,14 @@ from datetime import datetime, timedelta from typing import Optional import jwt +from fastapi import Depends, FastAPI, Security +from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from jwt import PyJWTError from passlib.context import CryptContext from pydantic import BaseModel from starlette.exceptions import HTTPException from starlette.status import HTTP_403_FORBIDDEN -from fastapi import Depends, FastAPI, Security -from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm - # to get a string like this run: # openssl rand -hex 32 SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" diff --git a/docs/tutorial/src/sql_databases/tutorial001.py b/docs/tutorial/src/sql_databases/tutorial001.py index 3b4336a86..a847c5c7b 100644 --- a/docs/tutorial/src/sql_databases/tutorial001.py +++ b/docs/tutorial/src/sql_databases/tutorial001.py @@ -1,4 +1,5 @@ from fastapi import FastAPI + from sqlalchemy import Boolean, Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base, declared_attr from sqlalchemy.orm import scoped_session, sessionmaker diff --git a/fastapi/applications.py b/fastapi/applications.py index a070b2b7f..2d5a0b862 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -1,5 +1,8 @@ from typing import Any, Callable, Dict, List, Optional, Type +from fastapi import routing +from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html +from fastapi.openapi.utils import get_openapi from pydantic import BaseModel from starlette.applications import Starlette from starlette.exceptions import ExceptionMiddleware, HTTPException @@ -8,10 +11,6 @@ from starlette.middleware.lifespan import LifespanMiddleware from starlette.requests import Request from starlette.responses import JSONResponse, Response -from fastapi import routing -from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html -from fastapi.openapi.utils import get_openapi - async def http_exception(request: Request, exc: HTTPException) -> JSONResponse: return JSONResponse({"detail": exc.detail}, status_code=exc.status_code) diff --git a/fastapi/dependencies/models.py b/fastapi/dependencies/models.py index eb4d1877b..748fe4a9e 100644 --- a/fastapi/dependencies/models.py +++ b/fastapi/dependencies/models.py @@ -1,8 +1,7 @@ from typing import Callable, List, Sequence -from pydantic.fields import Field - from fastapi.security.base import SecurityBase +from pydantic.fields import Field param_supported_types = (str, int, float, bool) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 575836c6a..ddf4f06db 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -3,6 +3,10 @@ import inspect from copy import deepcopy from typing import Any, Callable, Dict, List, Mapping, Sequence, Tuple, Type +from fastapi import params +from fastapi.dependencies.models import Dependant, SecurityRequirement +from fastapi.security.base import SecurityBase +from fastapi.utils import get_path_param_names from pydantic import BaseConfig, Schema, create_model from pydantic.error_wrappers import ErrorWrapper from pydantic.errors import MissingError @@ -12,11 +16,6 @@ from pydantic.utils import lenient_issubclass from starlette.concurrency import run_in_threadpool from starlette.requests import Request -from fastapi import params -from fastapi.dependencies.models import Dependant, SecurityRequirement -from fastapi.security.base import SecurityBase -from fastapi.utils import get_path_param_names - param_supported_types = (str, int, float, bool) diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index 698f1589f..0f0a03624 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -1,12 +1,5 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple, Type -from pydantic.fields import Field -from pydantic.schema import Schema, field_schema, get_model_name_map -from pydantic.utils import lenient_issubclass -from starlette.responses import JSONResponse -from starlette.routing import BaseRoute -from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY - from fastapi import routing from fastapi.dependencies.models import Dependant from fastapi.dependencies.utils import get_flat_dependant @@ -15,6 +8,12 @@ from fastapi.openapi.constants import METHODS_WITH_BODY, REF_PREFIX from fastapi.openapi.models import OpenAPI from fastapi.params import Body, Param from fastapi.utils import get_flat_models_from_routes, get_model_definitions +from pydantic.fields import Field +from pydantic.schema import Schema, field_schema, get_model_name_map +from pydantic.utils import lenient_issubclass +from starlette.responses import JSONResponse +from starlette.routing import BaseRoute +from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY validation_error_definition = { "title": "ValidationError", diff --git a/fastapi/routing.py b/fastapi/routing.py index 25ca651a4..fbd6a8d9c 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -3,6 +3,10 @@ import inspect import logging from typing import Any, Callable, List, Optional, Type +from fastapi import params +from fastapi.dependencies.models import Dependant +from fastapi.dependencies.utils import get_body_field, get_dependant, solve_dependencies +from fastapi.encoders import jsonable_encoder from pydantic import BaseConfig, BaseModel, Schema from pydantic.error_wrappers import ErrorWrapper, ValidationError from pydantic.fields import Field @@ -16,11 +20,6 @@ from starlette.responses import JSONResponse, Response from starlette.routing import get_name, request_response from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY -from fastapi import params -from fastapi.dependencies.models import Dependant -from fastapi.dependencies.utils import get_body_field, get_dependant, solve_dependencies -from fastapi.encoders import jsonable_encoder - def serialize_response(*, field: Field = None, response: Response) -> Any: if field: diff --git a/fastapi/security/api_key.py b/fastapi/security/api_key.py index c4b045b71..12eba37ee 100644 --- a/fastapi/security/api_key.py +++ b/fastapi/security/api_key.py @@ -1,7 +1,6 @@ -from starlette.requests import Request - from fastapi.openapi.models import APIKey, APIKeyIn from fastapi.security.base import SecurityBase +from starlette.requests import Request class APIKeyBase(SecurityBase): diff --git a/fastapi/security/http.py b/fastapi/security/http.py index 480a1ae54..b1cba1921 100644 --- a/fastapi/security/http.py +++ b/fastapi/security/http.py @@ -1,10 +1,9 @@ -from starlette.requests import Request - from fastapi.openapi.models import ( HTTPBase as HTTPBaseModel, HTTPBearer as HTTPBearerModel, ) from fastapi.security.base import SecurityBase +from starlette.requests import Request class HTTPBase(SecurityBase): diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index f190d805a..d915af184 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -1,13 +1,12 @@ from typing import List, Optional +from fastapi.openapi.models import OAuth2 as OAuth2Model, OAuthFlows as OAuthFlowsModel +from fastapi.security.base import SecurityBase from pydantic import BaseModel, Schema from starlette.exceptions import HTTPException from starlette.requests import Request from starlette.status import HTTP_403_FORBIDDEN -from fastapi.openapi.models import OAuth2 as OAuth2Model, OAuthFlows as OAuthFlowsModel -from fastapi.security.base import SecurityBase - class OAuth2PasswordRequestData(BaseModel): grant_type: str = "password" diff --git a/fastapi/security/open_id_connect_url.py b/fastapi/security/open_id_connect_url.py index b6c0a32dc..7d73ed81f 100644 --- a/fastapi/security/open_id_connect_url.py +++ b/fastapi/security/open_id_connect_url.py @@ -1,7 +1,6 @@ -from starlette.requests import Request - from fastapi.openapi.models import OpenIdConnect as OpenIdConnectModel from fastapi.security.base import SecurityBase +from starlette.requests import Request class OpenIdConnect(SecurityBase): diff --git a/fastapi/utils.py b/fastapi/utils.py index 81ca910cf..f3b4df82e 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -1,14 +1,13 @@ import re from typing import Any, Dict, List, Sequence, Set, Type +from fastapi import routing +from fastapi.openapi.constants import REF_PREFIX from pydantic import BaseModel from pydantic.fields import Field from pydantic.schema import get_flat_models_from_fields, model_process_schema from starlette.routing import BaseRoute -from fastapi import routing -from fastapi.openapi.constants import REF_PREFIX - def get_flat_models_from_routes( routes: Sequence[Type[BaseRoute]] diff --git a/scripts/test.sh b/scripts/test.sh index f39b89ee7..16add06c2 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -6,13 +6,13 @@ set -x export VERSION_SCRIPT="import sys; print('%s.%s' % sys.version_info[0:2])" export PYTHON_VERSION=`python -c "$VERSION_SCRIPT"` -export PYTHONPATH=.:./docs/tutorial/src +export PYTHONPATH=./docs/tutorial/src # PYTHONPATH=. pytest --cov=fastapi --cov=tests --cov-fail-under=100 --cov-report=term-missing ${@} --cov-report=html -pipenv run -- pytest --cov=fastapi --cov=tests --cov=docs/tutorial/src --cov-report=term-missing ${@} --cov-report=html -pipenv run -- mypy fastapi --disallow-untyped-defs +pytest --cov=fastapi --cov=tests --cov=docs/tutorial/src --cov-report=term-missing ${@} --cov-report=html +mypy fastapi --disallow-untyped-defs if [ "${PYTHON_VERSION}" = '3.7' ]; then echo "Skipping 'black' on 3.7. See issue https://github.com/ambv/black/issues/494" else - pipenv run -- black fastapi tests --check + black fastapi tests --check fi -pipenv run -- isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --check-only fastapi tests +isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --check-only fastapi tests diff --git a/tests/main_old.py b/tests/main_old.py index 1329ffcc3..468f4c764 100644 --- a/tests/main_old.py +++ b/tests/main_old.py @@ -1,7 +1,3 @@ -from pydantic import BaseModel -from starlette.responses import HTMLResponse, JSONResponse, PlainTextResponse -from starlette.status import HTTP_202_ACCEPTED - from fastapi import ( Body, Cookie, @@ -20,6 +16,9 @@ from fastapi.security import ( OAuth2PasswordBearer, OAuth2PasswordRequestForm, ) +from pydantic import BaseModel +from starlette.responses import HTMLResponse, JSONResponse, PlainTextResponse +from starlette.status import HTTP_202_ACCEPTED from .endpoints.a import router as router_a from .endpoints.b import router as router_b