]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Replace black with ruff formatter (#2330)
authorAmin Alaee <mohammadamin.alaee@gmail.com>
Wed, 8 Nov 2023 16:43:38 +0000 (17:43 +0100)
committerGitHub <noreply@github.com>
Wed, 8 Nov 2023 16:43:38 +0000 (17:43 +0100)
pyproject.toml
requirements.txt
scripts/check
scripts/lint
starlette/applications.py
starlette/middleware/authentication.py
starlette/middleware/errors.py
starlette/routing.py

index cb876b52e25b6d7355d84577a6a4812c64590d70..9909fb86a4237ebfd9e4468d26c687e42aa9916b 100644 (file)
@@ -51,10 +51,10 @@ Source = "https://github.com/encode/starlette"
 [tool.hatch.version]
 path = "starlette/__init__.py"
 
-[tool.ruff]
+[tool.ruff.lint]
 select = ["E", "F", "I"]
 
-[tool.ruff.isort]
+[tool.ruff.lint.isort]
 combine-as-imports = true
 
 [tool.mypy]
index d42666a4ad5d917742951f72d74b757c1852e45b..1e21c5a0319cc789c96e9ec7a356975c5c942071 100644 (file)
@@ -2,11 +2,10 @@
 -e .[full]
 
 # Testing
-black==23.10.1
 coverage==7.3.1
 importlib-metadata==6.8.0
 mypy==1.5.1
-ruff==0.1.3
+ruff==0.1.4
 typing_extensions==4.8.0
 types-contextvars==2.4.7.3
 types-PyYAML==6.0.12.12
index cc515ddaf6837e29502210fca553ed65d0e34fb6..7f169e3bcd5bfcdadf92c04a989e4819205a5695 100755 (executable)
@@ -9,7 +9,7 @@ export SOURCE_FILES="starlette tests"
 set -x
 
 ./scripts/sync-version
-${PREFIX}black --check --diff $SOURCE_FILES
+${PREFIX}ruff format --check --diff $SOURCE_FILES
 # TODO: Use `[[tool.mypy.overrides]]` on the `pyproject.toml` when the mypy issue is solved:
 # github.com/python/mypy/issues/10045. Check github.com/encode/starlette/pull/2180 for more info.
 ${PREFIX}mypy starlette
index e3f38e34662e53c91a58b31c6ab6c5af87f41da1..586aedfc3693fd178e8d0f827b0cd1911abdd1df 100755 (executable)
@@ -8,5 +8,5 @@ export SOURCE_FILES="starlette tests"
 
 set -x
 
-${PREFIX}black $SOURCE_FILES
+${PREFIX}ruff format $SOURCE_FILES
 ${PREFIX}ruff --fix $SOURCE_FILES
index cef4ace712508cc828c049abdb6014be2df0385a..8994211818e0e5b2361cf09e864ab269f5211678 100644 (file)
@@ -137,7 +137,9 @@ class Starlette:
         self.exception_handlers[exc_class_or_status_code] = handler
 
     def add_event_handler(
-        self, event_type: str, func: typing.Callable  # type: ignore[type-arg]
+        self,
+        event_type: str,
+        func: typing.Callable,  # type: ignore[type-arg]
     ) -> None:  # pragma: no cover
         self.router.add_event_handler(event_type, func)
 
@@ -208,9 +210,7 @@ class Starlette:
 
         return decorator
 
-    def websocket_route(
-        self, path: str, name: str | None = None
-    ) -> typing.Callable:  # type: ignore[type-arg]
+    def websocket_route(self, path: str, name: str | None = None) -> typing.Callable:  # type: ignore[type-arg]
         """
         We no longer document this decorator style API, and its usage is discouraged.
         Instead you should use the following approach:
index 76e4a246d2c0190627e388d43d28c5202d7c556b..21f097434352e133a5fbc2b345ac76f247804dc4 100644 (file)
@@ -24,7 +24,7 @@ class AuthenticationMiddleware:
         self.backend = backend
         self.on_error: typing.Callable[
             [HTTPConnection, AuthenticationError], Response
-        ] = (on_error if on_error is not None else self.default_on_error)
+        ] = on_error if on_error is not None else self.default_on_error
 
     async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
         if scope["type"] not in ["http", "websocket"]:
index f4c3d67461d74838d2288b165c65de5a1f45c9cf..c6336160ca79be4e919bcf958d71d094b1be7bbd 100644 (file)
@@ -201,7 +201,10 @@ class ServerErrorMiddleware:
     def generate_frame_html(self, frame: inspect.FrameInfo, is_collapsed: bool) -> str:
         code_context = "".join(
             self.format_line(
-                index, line, frame.lineno, frame.index  # type: ignore[arg-type]
+                index,
+                line,
+                frame.lineno,
+                frame.index,  # type: ignore[arg-type]
             )
             for index, line in enumerate(frame.code_context or [])
         )
index 9da6730ca018dc0ee3f9268f4099362fe1a4c4b8..38bb3517e9b7e6f68ed49f0c8f71c9cb466c793e 100644 (file)
@@ -565,7 +565,7 @@ class _AsyncLiftContextManager(typing.AsyncContextManager[_T]):
 def _wrap_gen_lifespan_context(
     lifespan_context: typing.Callable[
         [typing.Any], typing.Generator[typing.Any, typing.Any, typing.Any]
-    ]
+    ],
 ) -> typing.Callable[[typing.Any], typing.AsyncContextManager[typing.Any]]:
     cmgr = contextlib.contextmanager(lifespan_context)