]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
⬆️ Upgrade and fully migrate to Ruff, remove isort, includes a couple of tweaks sugge...
authorSebastián Ramírez <tiangolo@gmail.com>
Sun, 11 Jun 2023 22:37:34 +0000 (00:37 +0200)
committerGitHub <noreply@github.com>
Sun, 11 Jun 2023 22:37:34 +0000 (00:37 +0200)
.pre-commit-config.yaml
fastapi/openapi/utils.py
fastapi/routing.py
pyproject.toml
requirements-tests.txt
requirements.txt
scripts/format.sh
scripts/lint.sh
tests/test_empty_router.py

index 25e797d246b72f383d149dce04b264a5e79cd057..7050aa31c779fea7aec392c8d7a61ab9e0cbe263 100644 (file)
@@ -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:
index 86e15b46d30a35fddbc92f2dd993497c835f5e33..6d736647b5b03f3305e5e5e8f36d13e9e951d9ec 100644 (file)
@@ -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",
index af628f32d7d13f1643245b9b38ad2d1080b349c8..ec8af99b3a29045f3617f4190d293bbe3dab9730 100644 (file)
@@ -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:
index 69c42b254be1882c8c2eed5964ff6ec009ecd96b..5471371445d6839050b17328ce6fee0576068e80 100644 (file)
@@ -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
 ]
index 5105071be31c27e070918112e7511e90a57b7bfb..a98280677c69654f8edc569ebfd8e82ea2ca2c2b 100644 (file)
@@ -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
index 9d51e1cb3d9a2f9c8978227bac241669b289e30a..cb9abb44afe2492caf4a8adab238e31ac8c1ec2c 100644 (file)
@@ -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
index 3ac1fead86a4fca803728c34da5ef17d53b07cda..3fb3eb4f19df977e21a5923426375cc119067793 100755 (executable)
@@ -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
index 0feb973a87f46fb5c5cf8c8a8e02a52b91883b42..4db5caa9627eae5442b37c10ad40f8e89a090697 100755 (executable)
@@ -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
index 186ceb347e048ece748f8dd12257634db00d561c..1a40cbe304ac7903384a4c7758b577a860cf3f81 100644 (file)
@@ -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)