From d510cda4fe75d3356a9194f51dd89ebbbe87a7d8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 21:43:49 +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/routing.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index b5aa7f7e55..0d36cf4d82 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -25,6 +25,7 @@ from enum import Enum, IntEnum from typing import ( Annotated, Any, + TypedDict, TypeVar, cast, ) @@ -90,9 +91,7 @@ from starlette.routing import Mount as Mount # noqa from starlette.types import AppType, ASGIApp, Lifespan, Receive, Scope, Send from starlette.websockets import WebSocket from typing_extensions import deprecated -import inspect -import weakref -from typing import Any, TypedDict + # Copy of starlette.routing.request_response modified to include the # dependencies' AsyncExitStack @@ -256,12 +255,12 @@ class EndpointContext(TypedDict, total=False): function: str -# Use a WeakKeyDictionary instead of a standard dict to prevent memory leaks +# Use a WeakKeyDictionary instead of a standard dict to prevent memory leaks # and cache collisions when endpoints are dynamically created and destroyed. # This cache will only be used for the fallback "slow path"._endpoint_context_cache: weakref.WeakKeyDictionary[Any, EndpointContext] = weakref.WeakKeyDictionary() def _extract_endpoint_context(func: Any) -> EndpointContext: """Extract endpoint context with caching to avoid repeated file I/O.""" - + ctx: EndpointContext = {} # Fast path: Read __code__ directly. This is ~2000x faster than inspect,