From 20c4b7a077065a815f869dd2981e92e95d9a7793 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 07:08:06 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/security/http.py | 12 +++++++++--- tests/test_security_http_base_optional.py | 6 ++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fastapi/security/http.py b/fastapi/security/http.py index 081fb18ac..c7fd065b9 100644 --- a/fastapi/security/http.py +++ b/fastapi/security/http.py @@ -91,7 +91,9 @@ class HTTPBase(SecurityBase): headers=self.make_authenticate_headers(), ) - async def __call__(self, conn: HTTPConnection) -> HTTPAuthorizationCredentials | None: + async def __call__( + self, conn: HTTPConnection + ) -> HTTPAuthorizationCredentials | None: authorization = conn.headers.get("Authorization") scheme, credentials = get_authorization_scheme_param(authorization) if not (authorization and scheme and credentials): @@ -300,7 +302,9 @@ class HTTPBearer(HTTPBase): self.scheme_name = scheme_name or self.__class__.__name__ self.auto_error = auto_error - async def __call__(self, conn: HTTPConnection) -> HTTPAuthorizationCredentials | None: + async def __call__( + self, conn: HTTPConnection + ) -> HTTPAuthorizationCredentials | None: authorization = conn.headers.get("Authorization") scheme, credentials = get_authorization_scheme_param(authorization) if not (authorization and scheme and credentials): @@ -401,7 +405,9 @@ class HTTPDigest(HTTPBase): self.scheme_name = scheme_name or self.__class__.__name__ self.auto_error = auto_error - async def __call__(self, conn: HTTPConnection) -> HTTPAuthorizationCredentials | None: + async def __call__( + self, conn: HTTPConnection + ) -> HTTPAuthorizationCredentials | None: authorization = conn.headers.get("Authorization") scheme, credentials = get_authorization_scheme_param(authorization) if not (authorization and scheme and credentials): diff --git a/tests/test_security_http_base_optional.py b/tests/test_security_http_base_optional.py index 936e72acc..eae7bc0e6 100644 --- a/tests/test_security_http_base_optional.py +++ b/tests/test_security_http_base_optional.py @@ -1,5 +1,3 @@ -from typing import Optional - from fastapi import FastAPI, Security, WebSocket from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBase from fastapi.testclient import TestClient @@ -12,7 +10,7 @@ security = HTTPBase(scheme="Other", auto_error=False) @app.get("/users/me") def read_current_user( - credentials: Optional[HTTPAuthorizationCredentials] = Security(security), + credentials: HTTPAuthorizationCredentials | None = Security(security), ): if credentials is None: return {"msg": "Create an account first"} @@ -22,7 +20,7 @@ def read_current_user( @app.websocket("/users/timeline") async def read_user_timeline( websocket: WebSocket, - credentials: Optional[HTTPAuthorizationCredentials] = Security(security), + credentials: HTTPAuthorizationCredentials | None = Security(security), ): await websocket.accept() await websocket.send_json(