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

Skip to content

Commit fe453f8

Browse files
Brian Mboyatiangolo
andauthored
⬆ Upgrade isort to version 5.x.x (fastapi#1670)
* Update isort script to match changes in the new release, isort v5.0.2 * Downgrade isort to version v4.3.21 * Add an alternative flag to --recursive in isort v5.0.2 * Add isort config file * 🚚 Import from docs_src for tests * 🎨 Format dependencies.utils * 🎨 Remove isort combine_as_imports, keep black profile * 🔧 Update isort config, use pyproject.toml, Black profile * 🔧 Update format scripts to use explicit directories to format otherwise it would try to format venv env directories, I have several with different Python versions * 🎨 Format NoSQL tutorial after re-sorting imports * 🎨 Fix format for __init__.py Co-authored-by: Sebastián Ramírez <[email protected]>
1 parent 3ff504f commit fe453f8

97 files changed

Lines changed: 111 additions & 109 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/en/docs/advanced/nosql-databases.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You can adapt it to any other NoSQL database like:
1919

2020
For now, don't pay attention to the rest, only the imports:
2121

22-
```Python hl_lines="6 7 8"
22+
```Python hl_lines="3 4 5"
2323
{!../../../docs_src/nosql_databases/tutorial001.py!}
2424
```
2525

@@ -29,7 +29,7 @@ We will use it later as a fixed field `type` in our documents.
2929

3030
This is not required by Couchbase, but is a good practice that will help you afterwards.
3131

32-
```Python hl_lines="10"
32+
```Python hl_lines="9"
3333
{!../../../docs_src/nosql_databases/tutorial001.py!}
3434
```
3535

@@ -54,7 +54,7 @@ This utility function will:
5454
* Set defaults for timeouts.
5555
* Return it.
5656

57-
```Python hl_lines="13 14 15 16 17 18 19 20 21 22"
57+
```Python hl_lines="12 13 14 15 16 17 18 19 20 21"
5858
{!../../../docs_src/nosql_databases/tutorial001.py!}
5959
```
6060

@@ -66,7 +66,7 @@ As **Couchbase** "documents" are actually just "JSON objects", we can model them
6666

6767
First, let's create a `User` model:
6868

69-
```Python hl_lines="25 26 27 28 29"
69+
```Python hl_lines="24 25 26 27 28"
7070
{!../../../docs_src/nosql_databases/tutorial001.py!}
7171
```
7272

@@ -80,7 +80,7 @@ This will have the data that is actually stored in the database.
8080

8181
We don't create it as a subclass of Pydantic's `BaseModel` but as a subclass of our own `User`, because it will have all the attributes in `User` plus a couple more:
8282

83-
```Python hl_lines="32 33 34"
83+
```Python hl_lines="31 32 33"
8484
{!../../../docs_src/nosql_databases/tutorial001.py!}
8585
```
8686

@@ -100,7 +100,7 @@ Now create a function that will:
100100

101101
By creating a function that is only dedicated to getting your user from a `username` (or any other parameter) independent of your *path operation function*, you can more easily re-use it in multiple parts and also add <abbr title="Automated test, written in code, that checks if another piece of code is working correctly.">unit tests</abbr> for it:
102102

103-
```Python hl_lines="37 38 39 40 41 42 43"
103+
```Python hl_lines="36 37 38 39 40 41 42"
104104
{!../../../docs_src/nosql_databases/tutorial001.py!}
105105
```
106106

@@ -135,7 +135,7 @@ UserInDB(username="johndoe", hashed_password="some_hash")
135135

136136
### Create the `FastAPI` app
137137

138-
```Python hl_lines="47"
138+
```Python hl_lines="46"
139139
{!../../../docs_src/nosql_databases/tutorial001.py!}
140140
```
141141

@@ -145,7 +145,7 @@ As our code is calling Couchbase and we are not using the <a href="https://docs.
145145

146146
Also, Couchbase recommends not using a single `Bucket` object in multiple "<abbr title="A sequence of code being executed by the program, while at the same time, or at intervals, there can be others being executed too.">thread</abbr>s", so, we can get just get the bucket directly and pass it to our utility functions:
147147

148-
```Python hl_lines="50 51 52 53 54"
148+
```Python hl_lines="49 50 51 52 53"
149149
{!../../../docs_src/nosql_databases/tutorial001.py!}
150150
```
151151

docs_src/nosql_databases/tutorial001.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Optional
22

3-
from fastapi import FastAPI
4-
from pydantic import BaseModel
5-
63
from couchbase import LOCKMODE_WAIT
74
from couchbase.bucket import Bucket
85
from couchbase.cluster import Cluster, PasswordAuthenticator
6+
from fastapi import FastAPI
7+
from pydantic import BaseModel
98

109
USERPROFILE_DOC_TYPE = "userprofile"
1110

fastapi/dependencies/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
from pydantic.typing import ForwardRef, evaluate_forwardref
6161
except ImportError: # pragma: nocover
6262
# TODO: remove when removing support for Pydantic < 1.0.0
63+
from pydantic import Schema as FieldInfo # type: ignore
6364
from pydantic.fields import Field as ModelField # type: ignore
6465
from pydantic.fields import Required, Shape # type: ignore
65-
from pydantic import Schema as FieldInfo # type: ignore
6666
from pydantic.schema import get_annotation_from_schema # type: ignore
6767
from pydantic.utils import ForwardRef, evaluate_forwardref # type: ignore
6868

fastapi/security/http.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
from typing import Optional
44

55
from fastapi.exceptions import HTTPException
6-
from fastapi.openapi.models import (
7-
HTTPBase as HTTPBaseModel,
8-
HTTPBearer as HTTPBearerModel,
9-
)
6+
from fastapi.openapi.models import HTTPBase as HTTPBaseModel
7+
from fastapi.openapi.models import HTTPBearer as HTTPBearerModel
108
from fastapi.security.base import SecurityBase
119
from fastapi.security.utils import get_authorization_scheme_param
1210
from pydantic import BaseModel

fastapi/security/oauth2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import List, Optional
22

33
from fastapi.exceptions import HTTPException
4-
from fastapi.openapi.models import OAuth2 as OAuth2Model, OAuthFlows as OAuthFlowsModel
4+
from fastapi.openapi.models import OAuth2 as OAuth2Model
5+
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
56
from fastapi.param_functions import Form
67
from fastapi.security.base import SecurityBase
78
from fastapi.security.utils import get_authorization_scheme_param

fastapi/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
PYDANTIC_1 = True
1919
except ImportError: # pragma: nocover
2020
# TODO: remove when removing support for Pydantic < 1.0.0
21-
from pydantic.fields import Field as ModelField # type: ignore
2221
from pydantic import Schema as FieldInfo # type: ignore
22+
from pydantic.fields import Field as ModelField # type: ignore
2323

2424
class UndefinedType: # type: ignore
2525
def __repr__(self) -> str:

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,7 @@ all = [
9191
"async_exit_stack",
9292
"async_generator"
9393
]
94+
95+
[tool.isort]
96+
profile = "black"
97+
known_third_party = ["fastapi", "pydantic", "starlette"]

scripts/format-imports.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
set -x
33

44
# Sort imports one per line, so autoflake can remove unused imports
5-
isort --recursive --force-single-line-imports --thirdparty fastapi --apply fastapi tests docs_src scripts
5+
isort fastapi tests docs_src scripts --force-single-line-imports
66
sh ./scripts/format.sh

scripts/format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ set -x
33

44
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place docs_src fastapi tests scripts --exclude=__init__.py
55
black fastapi tests docs_src scripts
6-
isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --thirdparty fastapi --thirdparty pydantic --thirdparty starlette --apply fastapi tests docs_src scripts
6+
isort fastapi tests docs_src scripts

scripts/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -x
55

66
mypy fastapi
77
black fastapi tests --check
8-
isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --check-only --thirdparty fastapi --thirdparty fastapi --thirdparty pydantic --thirdparty starlette fastapi tests
8+
isort fastapi tests docs_src scripts --check-only

0 commit comments

Comments
 (0)