mirror of https://github.com/tiangolo/fastapi.git
⬆️ Upgrade and fully migrate to Ruff, remove isort, includes a couple of tweaks suggested by the new version of Ruff (#9660)
This commit is contained in:
parent
ba882c10fe
commit
7167c77a18
|
|
@ -21,22 +21,11 @@ repos:
|
|||
- --py3-plus
|
||||
- --keep-runtime-typing
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
rev: v0.0.254
|
||||
rev: v0.0.272
|
||||
hooks:
|
||||
- id: ruff
|
||||
args:
|
||||
- --fix
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.12.0
|
||||
hooks:
|
||||
- id: isort
|
||||
name: isort (python)
|
||||
- id: isort
|
||||
name: isort (cython)
|
||||
types: [cython]
|
||||
- id: isort
|
||||
name: isort (pyi)
|
||||
types: [pyi]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.1.0
|
||||
hooks:
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ def get_openapi_operation_metadata(
|
|||
file_name = getattr(route.endpoint, "__globals__", {}).get("__file__")
|
||||
if file_name:
|
||||
message += f" at {file_name}"
|
||||
warnings.warn(message)
|
||||
warnings.warn(message, stacklevel=1)
|
||||
operation_ids.add(operation_id)
|
||||
operation["operationId"] = operation_id
|
||||
if route.deprecated:
|
||||
|
|
@ -332,10 +332,8 @@ def get_openapi_path(
|
|||
openapi_response["description"] = description
|
||||
http422 = str(HTTP_422_UNPROCESSABLE_ENTITY)
|
||||
if (all_route_params or route.body_field) and not any(
|
||||
[
|
||||
status in operation["responses"]
|
||||
for status in [http422, "4XX", "default"]
|
||||
]
|
||||
status in operation["responses"]
|
||||
for status in [http422, "4XX", "default"]
|
||||
):
|
||||
operation["responses"][http422] = {
|
||||
"description": "Validation Error",
|
||||
|
|
|
|||
|
|
@ -30,7 +30,11 @@ from fastapi.dependencies.utils import (
|
|||
solve_dependencies,
|
||||
)
|
||||
from fastapi.encoders import DictIntStrAny, SetIntStr, jsonable_encoder
|
||||
from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
|
||||
from fastapi.exceptions import (
|
||||
FastAPIError,
|
||||
RequestValidationError,
|
||||
WebSocketRequestValidationError,
|
||||
)
|
||||
from fastapi.types import DecoratedCallable
|
||||
from fastapi.utils import (
|
||||
create_cloned_field,
|
||||
|
|
@ -48,14 +52,15 @@ from starlette.concurrency import run_in_threadpool
|
|||
from starlette.exceptions import HTTPException
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import JSONResponse, Response
|
||||
from starlette.routing import BaseRoute, Match
|
||||
from starlette.routing import Mount as Mount # noqa
|
||||
from starlette.routing import (
|
||||
BaseRoute,
|
||||
Match,
|
||||
compile_path,
|
||||
get_name,
|
||||
request_response,
|
||||
websocket_session,
|
||||
)
|
||||
from starlette.routing import Mount as Mount # noqa
|
||||
from starlette.types import ASGIApp, Lifespan, Scope
|
||||
from starlette.websockets import WebSocket
|
||||
|
||||
|
|
@ -763,7 +768,7 @@ class APIRouter(routing.Router):
|
|||
path = getattr(r, "path") # noqa: B009
|
||||
name = getattr(r, "name", "unknown")
|
||||
if path is not None and not path:
|
||||
raise Exception(
|
||||
raise FastAPIError(
|
||||
f"Prefix and path cannot be both empty (path operation: {name})"
|
||||
)
|
||||
if responses is None:
|
||||
|
|
|
|||
|
|
@ -66,10 +66,6 @@ all = [
|
|||
[tool.hatch.version]
|
||||
path = "fastapi/__init__.py"
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
known_third_party = ["fastapi", "pydantic", "starlette"]
|
||||
|
||||
[tool.mypy]
|
||||
strict = true
|
||||
|
||||
|
|
@ -125,7 +121,7 @@ select = [
|
|||
"E", # pycodestyle errors
|
||||
"W", # pycodestyle warnings
|
||||
"F", # pyflakes
|
||||
# "I", # isort
|
||||
"I", # isort
|
||||
"C", # flake8-comprehensions
|
||||
"B", # flake8-bugbear
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
pytest >=7.1.3,<8.0.0
|
||||
coverage[toml] >= 6.5.0,< 8.0
|
||||
mypy ==1.3.0
|
||||
ruff ==0.0.138
|
||||
ruff ==0.0.272
|
||||
black == 23.1.0
|
||||
isort >=5.0.6,<6.0.0
|
||||
httpx >=0.23.0,<0.24.0
|
||||
email_validator >=1.1.1,<2.0.0
|
||||
# TODO: once removing databases from tutorial, upgrade SQLAlchemy
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
-e .[all]
|
||||
-r requirements-tests.txt
|
||||
-r requirements-docs.txt
|
||||
ruff ==0.0.138
|
||||
uvicorn[standard] >=0.12.0,<0.21.0
|
||||
pre-commit >=2.17.0,<3.0.0
|
||||
|
|
|
|||
|
|
@ -3,4 +3,3 @@ set -x
|
|||
|
||||
ruff fastapi tests docs_src scripts --fix
|
||||
black fastapi tests docs_src scripts
|
||||
isort fastapi tests docs_src scripts
|
||||
|
|
|
|||
|
|
@ -6,4 +6,3 @@ set -x
|
|||
mypy fastapi
|
||||
ruff fastapi tests docs_src scripts
|
||||
black fastapi tests --check
|
||||
isort fastapi tests docs_src scripts --check-only
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import pytest
|
||||
from fastapi import APIRouter, FastAPI
|
||||
from fastapi.exceptions import FastAPIError
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
|
|
@ -31,5 +32,5 @@ def test_use_empty():
|
|||
|
||||
def test_include_empty():
|
||||
# if both include and router.path are empty - it should raise exception
|
||||
with pytest.raises(Exception):
|
||||
with pytest.raises(FastAPIError):
|
||||
app.include_router(router)
|
||||
|
|
|
|||
Loading…
Reference in New Issue