Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7167c77

Browse filesBrowse files
authored
⬆️ Upgrade and fully migrate to Ruff, remove isort, includes a couple of tweaks suggested by the new version of Ruff (#9660)
1 parent ba882c1 commit 7167c77
Copy full SHA for 7167c77

File tree

Expand file treeCollapse file tree

9 files changed

+17
-32
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+17
-32
lines changed

‎.pre-commit-config.yaml

Copy file name to clipboardExpand all lines: .pre-commit-config.yaml
+1-12Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,11 @@ repos:
2121
- --py3-plus
2222
- --keep-runtime-typing
2323
- repo: https://github.com/charliermarsh/ruff-pre-commit
24-
rev: v0.0.254
24+
rev: v0.0.272
2525
hooks:
2626
- id: ruff
2727
args:
2828
- --fix
29-
- repo: https://github.com/pycqa/isort
30-
rev: 5.12.0
31-
hooks:
32-
- id: isort
33-
name: isort (python)
34-
- id: isort
35-
name: isort (cython)
36-
types: [cython]
37-
- id: isort
38-
name: isort (pyi)
39-
types: [pyi]
4029
- repo: https://github.com/psf/black
4130
rev: 23.1.0
4231
hooks:

‎fastapi/openapi/utils.py

Copy file name to clipboardExpand all lines: fastapi/openapi/utils.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def get_openapi_operation_metadata(
181181
file_name = getattr(route.endpoint, "__globals__", {}).get("__file__")
182182
if file_name:
183183
message += f" at {file_name}"
184-
warnings.warn(message)
184+
warnings.warn(message, stacklevel=1)
185185
operation_ids.add(operation_id)
186186
operation["operationId"] = operation_id
187187
if route.deprecated:
@@ -332,10 +332,8 @@ def get_openapi_path(
332332
openapi_response["description"] = description
333333
http422 = str(HTTP_422_UNPROCESSABLE_ENTITY)
334334
if (all_route_params or route.body_field) and not any(
335-
[
336-
status in operation["responses"]
337-
for status in [http422, "4XX", "default"]
338-
]
335+
status in operation["responses"]
336+
for status in [http422, "4XX", "default"]
339337
):
340338
operation["responses"][http422] = {
341339
"description": "Validation Error",

‎fastapi/routing.py

Copy file name to clipboardExpand all lines: fastapi/routing.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
solve_dependencies,
3131
)
3232
from fastapi.encoders import DictIntStrAny, SetIntStr, jsonable_encoder
33-
from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
33+
from fastapi.exceptions import (
34+
FastAPIError,
35+
RequestValidationError,
36+
WebSocketRequestValidationError,
37+
)
3438
from fastapi.types import DecoratedCallable
3539
from fastapi.utils import (
3640
create_cloned_field,
@@ -48,14 +52,15 @@
4852
from starlette.exceptions import HTTPException
4953
from starlette.requests import Request
5054
from starlette.responses import JSONResponse, Response
51-
from starlette.routing import BaseRoute, Match
52-
from starlette.routing import Mount as Mount # noqa
5355
from starlette.routing import (
56+
BaseRoute,
57+
Match,
5458
compile_path,
5559
get_name,
5660
request_response,
5761
websocket_session,
5862
)
63+
from starlette.routing import Mount as Mount # noqa
5964
from starlette.types import ASGIApp, Lifespan, Scope
6065
from starlette.websockets import WebSocket
6166

@@ -763,7 +768,7 @@ def include_router(
763768
path = getattr(r, "path") # noqa: B009
764769
name = getattr(r, "name", "unknown")
765770
if path is not None and not path:
766-
raise Exception(
771+
raise FastAPIError(
767772
f"Prefix and path cannot be both empty (path operation: {name})"
768773
)
769774
if responses is None:

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ all = [
6666
[tool.hatch.version]
6767
path = "fastapi/__init__.py"
6868

69-
[tool.isort]
70-
profile = "black"
71-
known_third_party = ["fastapi", "pydantic", "starlette"]
72-
7369
[tool.mypy]
7470
strict = true
7571

@@ -125,7 +121,7 @@ select = [
125121
"E", # pycodestyle errors
126122
"W", # pycodestyle warnings
127123
"F", # pyflakes
128-
# "I", # isort
124+
"I", # isort
129125
"C", # flake8-comprehensions
130126
"B", # flake8-bugbear
131127
]

‎requirements-tests.txt

Copy file name to clipboardExpand all lines: requirements-tests.txt
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
pytest >=7.1.3,<8.0.0
33
coverage[toml] >= 6.5.0,< 8.0
44
mypy ==1.3.0
5-
ruff ==0.0.138
5+
ruff ==0.0.272
66
black == 23.1.0
7-
isort >=5.0.6,<6.0.0
87
httpx >=0.23.0,<0.24.0
98
email_validator >=1.1.1,<2.0.0
109
# TODO: once removing databases from tutorial, upgrade SQLAlchemy

‎requirements.txt

Copy file name to clipboard
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-e .[all]
22
-r requirements-tests.txt
33
-r requirements-docs.txt
4-
ruff ==0.0.138
54
uvicorn[standard] >=0.12.0,<0.21.0
65
pre-commit >=2.17.0,<3.0.0

‎scripts/format.sh

Copy file name to clipboardExpand all lines: scripts/format.sh
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ set -x
33

44
ruff fastapi tests docs_src scripts --fix
55
black fastapi tests docs_src scripts
6-
isort fastapi tests docs_src scripts

‎scripts/lint.sh

Copy file name to clipboardExpand all lines: scripts/lint.sh
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ set -x
66
mypy fastapi
77
ruff fastapi tests docs_src scripts
88
black fastapi tests --check
9-
isort fastapi tests docs_src scripts --check-only

‎tests/test_empty_router.py

Copy file name to clipboardExpand all lines: tests/test_empty_router.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from fastapi import APIRouter, FastAPI
3+
from fastapi.exceptions import FastAPIError
34
from fastapi.testclient import TestClient
45

56
app = FastAPI()
@@ -31,5 +32,5 @@ def test_use_empty():
3132

3233
def test_include_empty():
3334
# if both include and router.path are empty - it should raise exception
34-
with pytest.raises(Exception):
35+
with pytest.raises(FastAPIError):
3536
app.include_router(router)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.